extract the first column from a file: awk '{print $1}' file
renaming files (append ‘.new’): ls files_list | awk '{print "mv "$1" "$1".new"}' | sh
renaming within a name: ls -1 *old* | awk '{print "mv "$1" "$1}' | sed s/old/new/2 | sh
remove only files:
ls -l * | grep -v drwx | awk '{print "rm "$9}' | shls -l|awk '$1!~/^drwx/{print $9}'|xargs rmremove only directories:
ls -l | grep '^d' | awk '{print "rm -r "$9}' | shls -p | grep /$ | wk '{print "rm -r "$1}'ls -l|awk '$1~/^d.*x/{print $9}'|xargs rm -rkilling processes by name, eg. netscape:
kill ps auxww | grep netscape | egrep -v grep | awk '{print $2}'ps auxww | awk '$0~/netscape/&&$0!~/awk/{print $2}' |xargs killrearranging columns:
1234 HD 13324 22:40:541235 HD122235 22:43:1222:40:54 1234 HD 1332422:43:12 1235 HD122235pretty printing tables (with header & footer)
awk 'BEGIN { print "Month Crates"
print "----- ------" }
{ print $1, " ", $2 }
END { print "----- ------" }' testfile
Jan 13 Feb 15 Mar 15
working over a subset of lines instead of all lines in file
awk '/^127.0.0.1 missscatterbrain/ {print}' /etc/hostsawk -F: '$7 ~ /bash/ {print $1}' /etc/passwd | sortas a programming language
gawk