cut — CUT a specified part form the file and Print it on stdout.Summary :
Print selected parts of lines from each file(s) to standard output. Create file1 with 10 columns (separated by TAB) of data for 10 lines and file2 with 10 columns (separated by space) of data for 10 lines. Examples :
$ cut -b2 file1 -- Print only the byte in 2 position. Tab andBackspace are treated like a 1 byte char. $ cut -b1,3,5 file1 -- Print only the bytes at 1,3 and 5. $ cut -c2 file1 -- Print only character in 2nd position. It issame as -b option. But you can feel the difference only withmulti-byte encodings (Unicode). $ cut -f5 file1 -- Print only the 6th field. Default delimiteror separator is TAB. $ cut -f4- file1 -- Print from 4th field to last field. $ cut -f-5 file1 -- Print from 1st field to 4th field. $ cut -d' ' -f3-5 file2 -- Print only the fields from 3 to 5,which are separated by spaces. $ cut -s -d' ' -f2 file2 -- Don't print lines that does notcontain the delimiter (space). Normally the line without adelimiter will be printed as it is. $ cut -f2-5,7-9 --output-delimiter=',' file1 -- In the output, fields will be separated by "," (Default is space).Note:
1) Use one, and only one of -b, -c or -f.
2) Range or many ranges can be separated by commas.
3) Range of Bytes/Chars/Fields can specified like this:
N == Only Nth byte, character or field.
N- == From Nth byte, character or field, to End of line.
N-M == From Nth to Mth (included) byte, character or field.
-M == From 1st to Mth (included) byte, character or field. Read : man cut