The CLI tools you need to know
cut
cut
takes a delimiter (-d
) and splits input on that delimiter (like String.Split()
or String.Fields()
in many programming languages). You then select which field (list element) you want to output with -f
, e.g. f1
for the first field.
If you feed cut
more than one line, it will repeat that same operation on all lines.
# echo "this is a space-delimited line" | cut -d " " -f4
space-delimited
To get friendly names for all users with ‘root’ in their names (on an OS X machine):
# grep root /etc/passwd | cut -d ":" -f5
System Administrator
System Services
CVMS Root
sort
sort
does a per-line sorting (alphabetial or numeric).
Reverse-sorting with -r
is often useful when dealing with numeric data (-n
). You’ll often want -rn
together (see “Top X” in the patterns section of this chapter).
The -h
flag can be very useful for sorting by human readable output of many other commands, like this:
...