Friday, 9 December 2016

Use of cut command

Cut : This command is used to extract or divide specific fields and characters from a given file based on delimiters.
                           Syntax:$cut (fields) or (delimiter) or (character) <filename>
Ex:
$cut -f 1,3 jobs
It displays 1st and 3rd fields from jobs file.
-f means field by field.
Note: Default delimiter is tab.
When default delimiter is tab that's why no need to mention it,but if delimiter is other than tab we have to mention that delimiter.

Ex:
$cut -f 2-4 jobs
It displays 2nd fields to 4th fields.
Ex:
$cut -f 2- jobs
It displays 2nd field to last field from jobs file.
Ex:
$cut -d "," -f 1,3 countries
It displays 1st and 3rd fields from countries file.
Here in countries file all fields separated by comm delimiter.So, we have to mention it,

Ex:
$cut -c 1-10 jobs
It displays every row 1st character to 10th character from jobs file.

Ex:
$cut 1-5,10-15 jobs
It displays every row 1st character to 5th character and from 10th character to 15th character.

No comments:

Post a Comment