We have moved to www.dataGenX.net, Keep Learning with us.

Tuesday, June 26, 2012

cut – Splitting a file vertically


The external cut command displays selected columns or fields from each line of a file.
-c     Cutting columns
to cutting specific columns, you need to follow the -c option with a list of column numbers, delimit by a comma. Range can also be used using the hyphen.

$ cut -c 6-22,24-26 emp.list

this command extract the data, from file, from 6th char to 22th and 24th char to 26th characters .

$ cut -c 2,3-4.6-12,15 emp.list

-f      Cutting fields
to extract useful data from these files u need to cut fields rather than columns. Cut use the tab as the default field delimiter, but can also work with a different delimiter. Option -d specified a single character delimiter which serves as field separator.Two option need to be used here : -d for the field delimiter and -f for the field list.

$ cut -d “|” -f2,3 emp.list

it extract the field 2,3 which is delimit by |.
** One of the option -c and -f must be specified. These option are really not optional, one of them is compulsory.
njoy the simplicity.......
Atul Singh

No comments :

Post a Comment