Friday, February 5, 2016

Cut

Cut is a command that allows you to output certain portions of the line. it gives you many ways to do this:

delimiters and field lists:

delimiters and field lists allow you to chunk out lines separated by characters for instance:
head -n 1 etc/passwd/ |cut -d ':' -f 1
outputs:
root

as you can see -d is the delimiter and -f is the field list. here the character they are separated by is ':' and the section they are showing is 1. you can even use -s to bypass lines that dont contain field delimiters

charicters:

characters are the simplest way to use cut. it just outputs the characters in a range. for example:

head -n 1 etc/passwd/ |cut -c 2-4
outputs:
oot

as you can see -c is the character range.

bytes:

bytes allows you to specify the amount of bytes you want the output to take up. I am not going to give an example for this. all you need to know is that -b is bytes. 

No comments:

Post a Comment