Cut command is used to extract specific columns of a file or multiple files
Examples:
Let’s say a sample file xyz.txt has below content
Cat xyz.txt
To display 6th character from left from each line of the file: cut –c 6 xyz.txt
To display a range of columns , let’s say 2nd thru 7th column in file :
cut –c 2-7 xyz.txt
To display from nth column till the last column: cut –c 9- xyz.txt
To display first nth column:
cut –c -4 xyz.txt
To display second field till the end of line using colon (:) as the field delimiter:
cut –d “:” –f 2- xyz.txt
To display multiple range of columns in a file:
cut –d “:” –f 2-3 xyz.txt
To display set of ranges of column in a file:
cut –d “:” –f 2-3, 5-6 xyz.txt
To display specific columns in a file:
cut –d “:” –f 2,5 xyz.txt
To display all columns except certain , use –complement as
cut –d “:” – -complement –f 2 xyz.txt
To display from 2nd character till the end of line in each row, use
cut –c2- xyz.txt
To display all lines, cut –c- xyz.txt
To replace output delimiter with a new character , use
cut –d “:” –s –f 2,5 xyz.txt – – output ’%’
Buy Indian Boutique Embroidered Pure Georgette Anarkali Designer Dress … from Snapdeal
To split the rows to new rows after each delimiter, use
cut -d “:” -s -f 2,5 xyz.txt –output $’\n’