cut command with examples in Linux / Unix

cut command with examples in Linux / Unix

Cut command is one of the most use able text processing command. It is used to filter the text content by field, character, bytes and deliminator wise. Even if the file is having more than 1000 lines using the cut command we can extract it according to our needs.

 

cut command with examples in Linux / Unix
Options of cut command:

-c —– To select content character,
-b —– Select in bytes,
-f —–  To select the field and
-d —– Deliminator used to select field and by default TAB is the deliminator.

Cut the field 1 with deliminator “:”

#cat /etc/passwd | cut -d':’ -f1

Cut the 2nd and 6th field with deliminator “:”

#cat /etc/shadow | cut -d”:” -f2,6

Cut the field range from “1 to 6″.

#cat /etc/passwd | cut -d”:” -f1,5

Command to cut the exact 6th letter from the line

#cat /etc/passwd | tail -1 | cut -c 6

Command to cut the 3rd, 4th and 5th letter from the line

#cat /etc/passwd | tail -1 | cut -c 3,4,5

Command to cut letter from 3rd to 9th letter from the line

#cat /etc/passwd | tail -1 | cut -c 3-9

Command to cut the exact 6th letter from the line

#cat /etc/passwd | tail -1 | cut -b 6

Command to cut the 3rd, 4th and 5th letter from the line

#cat /etc/passwd | tail -1 | cut -b 3,4,5

Command to cut letter from 3rd to 9th letter from the line

#cat /etc/passwd | tail -1 | cut -b 3-9

 




Leave a Reply

Your email address will not be published. Required fields are marked *