You are on page 1of 1

CUT,PASTE & JOIN

*CUT [to cut portions of a file]

Syntax:

cut options filename

1) cut -c2 filename # Cuts the second character of all lines and prints them

2) cut -c2-5 filename # Cuts characters from 2nd to 5th position and prints them

3) cut -c3- filename # Cuts and prints from 3rd character till the end

4) cut -c-8 filename # cuts from the 1st character till the 8th character and
prints

#To cut only specific field among the multiple fields

1) cut -d "," -f2 filename # cuts the 2nd field from the file and prints

2) cut -d "," -f2,3 filename # cuts 2nd and 3frd fields from the file and prints

3) cut -d "," -f2-5 filename # cuts all fields from 2 to 5

#Try with other options

*PASTE [to merge contents of multiple files]

Suntax:
paste options file-1 file-2 file-n

1) paste filename1 filename2 #merges contents of first file and second file

2) paste -d "," filename1 filemane2 #merges contents of fisrt file and second file
seperating them with a comma

3) paste -s filename1 filename2 #merges the contents in sequential order

4) paste -s -d "," filename1 filename2 #merges in sequential order seperating each


word with a comma

5) paste -s -d ",/" filename1 filename2 #adds multiple delimiters

6) cat filename | paste - - - # pastes the 3 lines of the file in a single line

You might also like