Search This Blog

2014-07-31

Using Cut to filter output

Cut is a simple unix utility which "cuts" out specific characters,bytes,etc from a specified output.

The most common way to use cut is either using a range (cut 4-10 characters) our of the file named file
cut -c 4-10 file

The second most common is to specify a delimiter so that you only print a certain field
cut -d "-" -f 2-
Use the dash as a field separator and print all fields from field 2 to the end of the file.

This can then be merged with sed to remove the fields later
cut -d "-" -f 2- | sed 's/-//'

No comments:

Post a Comment