cut command displays the selected columns or fields from each line of a file.
Column selection mode:
A column is one character position. This type of selection is specified with -c option. List entries can be open (from the beginning like in -5, or to the end like in 6-), or closed (like 6-9).
cut -c 4,5,20 foo # cuts foo at columns 4, 5, and 20
cut -c 1-5 a.dat | more # print the first 5 characters of every line in the file a.dat
Field selection mode:
In this mode cut selects not characters but fields delimited by specifiec one character delimiter specified by option -d. The list of fields is specified with -f option ( -f [list] )
cut -d ":" -f1,7 /etc/passwd # cuts fields 1 and 7 from /etc/passwd cut -d ":" -f 1,6- /etc/passwd # cuts fields 1, 6 to the end from /etc/passwd
The default delimiter is TAB. If space is used as a delimiter, be sure to put it in quotes (-d " ").
0 comments:
Post a Comment