8.6.18 Script snippets for piping commands
The following scripts will do nice things as a part of a pipe.
find /usr | egrep -v "/usr/var|/usr/tmp|/usr/local"
# find all files in /usr excluding some files
xargs -n 1 command # run command for all items from stdin
xargs -n 1 echo | # split white-space-separated items into lines
xargs echo | # merge all lines into a line
grep -e pattern| # extract lines containing pattern
cut -d: -f3 -|
# extract third field separated by : (passwd file etc.)
awk '{ print $3 }' | # extract third field separated by whitespaces
awk -F'\t' '{ print $3 }' |
# extract third field separated by tab
col -bx | # remove backspace and expand tabs to spaces
expand -| # expand tabs
sort -u| # sort and remove duplicates
tr '\n' ' '| # concatenate lines into one line
tr '\r' ''| # remove CR
tr 'A-Z' 'a-z'| # convert uppercase to lowercase
sed 's/^/# /'| # make each line a comment
sed 's/\.ext//g'| # remove .ext
sed -n -e 2p| # print the second line
head -n 2 -| # print the first 2 lines
tail -n 2 -| # print the last 2 lines