utility cut
To extract selected characters or fields from standard input or from a file, use the utility cut command in XR EXEC mode.
utility cut { {list character-list | fields field-list [nodelim] [delimiter delimiter-character] | WORD} [file input-file] | usage}
Syntax Description
list character-list |
(-c) Cuts out the characters that are located on each line as specified with the character-list argument. The character-list argument specifies the character positions or range of the characters to be cut.
|
||
fields field-list |
(-f) Cuts out the fields (lines) as indicated with the field-list argument. The field-list argument specifies the field numbers or ranges. For example, utility field 2,9 outputs the second and ninth fields, utility field 1-3 outputs the first three fields, utility field -6 outputs the first six fields.
|
||
nodelim |
(Optional) (-s) Ignores lines with no delimiter. Use this optional keyword when the fields field-list keyword and argument is specified. |
||
delimiter delimiter-character |
(Optional) (-d) Specifies an alternative delimiter to indicate the end of each field. Replace the delimiter-character argument with the character used as the delimiter. |
||
WORD |
(Optional) UNIX command-line option string. The maximum number of characters is 80. |
||
file input-file |
(Optional) Storage device and directory path of the text file used instead of the standard input (keyboard input). The syntax of the input-file argument is: device :[/ directory-path]/ filename The device argument, followed by a colon, indicates the name of the device where the file is located. Use the online help (? ) function to display the available storage devices and network protocols. |
||
usage |
(Optional) Displays the UNIX options supported by this command. |
Command Default
If no file is specified, keyboard input (standard input) is used.
The default for delimiter is tab.
Command Modes
XR EXEC
Command History
Release | Modification |
---|---|
Release 7.0.1 |
This command was introduced. |
Usage Guidelines
The utility cut command cuts out columns, fields, or characters displayed from standard input or from a file.
Use the fields field-list keyword and argument if the fields vary in length from line to line. (The lines must be separated by a delimiter character.) By default, the field delimiter character is the Tab key. Use the delimiter delimiter-character keyword and argument to specify a different delimiter.
Use the list character-list keyword and argument only if the fields are of a fixed length. Replace the character-list argument with the character positions to be extracted.
For the character-list argument, use a comma (,) to indicate more than one character, or use a dash (-) to indicate a range. For example, utility list 1,2,5 outputs the first, second, and fifth characters, utility list 1-64 outputs the first 64 characters of each line, utility list 5- outputs the fifth character to the end of the line.
You can also use the cut utility as a filter. If no files are specified, the keyboard input (standard input) is used.
Note |
Keywords are entered using the displayed syntax, or with UNIX-equivalent syntax. The UNIX-equivalent syntax is displayed in parentheses () in the syntax description. For example, the fields keyword can also be entered using the UNIX-equivalent (-f). To display the UNIX-equivalent syntax online, enter the usage keyword. |
Examples
In the following example, the utility cut command is entered with the list character-list keyword and argument to display the first 10 characters in each line. The output is from the results of the show version command, which is entered with the pipe (|) character:
RP/0/RP0/CPU0:router# show version | utility cut list 1-10
Cisco IOS
Copyright
ROM: Syste
router upt
System ima
cisco CRS-
7457 proce
16 Gigabit
2 Ethernet
20 Packet
20 SONET/S
2043k byte
38079M byt
1000592k b
1000640k b
Configurat
Package ac
--More--
In the following example, the utility cut command is used to extract fields from a file:
RP/0/RP0/CPU0:router# utility cut fields 1,5 delimiter : file disk0:/usr/passwd
root:Super-User
daemon:
bin:
sys:
adm:Admin
lp:Line Printer Admin
uucp:uucp Admin
nuucp:uucp Admin
listen:Network Admin
nobody:Nobody
In the following example, the utility cut command is used with the delimiter keyword to specify an alternative field delimiter:
RP/0/RP0/CPU0:router# utility cut fields 1,4,5 delimiter : file disk0:/usr/passwd
root:1:Super-User
daemon:1:
bin:2:
sys:3:
adm:4:Admin
lp:8:Line Printer Admin
uucp:5:uucp Admin
nuucp:9:uucp Admin
listen:4:Network Admin
In the following example, a range of fields is specified:
RP/0/RP0/CPU0:router# utility cut fields 1-4 delimiter : file disk0:/usr/passwd
root:x:0:1
daemon:x:1:1
bin:x:2:2
sys:x:3:3
adm:x:4:4
lp:x:71:8
uucp:x:5:5
nuucp:x:9:9
listen:x:37:4
In the following example, the list character-list keyword and argument are used to specify the character positions to be extracted:
RP/0/RP0/CPU0:router# utility cut list 1-30 file disk0:/usr/passwd
root:x:0:1:Super-User:/:/sbin/
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/
uucp:x:5:5:uucp Admin:/usr/lib
nuucp:x:9:9:uucp Admin:/var/sp
listen:x:37:4:Network Admin:/u
nobody:x:60001:60001:Nobody:/:
noaccess:x:60002:60002:No Acce
nobody4:x:65534:65534:SunOS 4.
==========================================================================
In the following example, the UNIX equivalent options are used directly. First, the utility cut command is entered with the usage keyword to display the possible options. Next, the utility cut command is entered with the options to extract the desired data.
RP/0/RP0/CPU0:router# utility cut usage
cut -c list [file], cut -f list [-d delim] [-s] [file]
RP/0/RP0/CPU0:router# utility cut -f 1,4 -d : disk0:/usr/passwd
root:1
daemon:1
bin:2
sys:3
adm:4
lp:8