Sed Awk Commands
Sed Awk Commands
awk '{ print $NF }' print the last field of each line
awk '{print NR "\t" $0}' file.txt precede each line by its line number FOR ALL FILES
ls -lrt | awk '{ print NF ":" $0 } ' print the no of fields of each line
ls -lrt | awk 'NF > 4' print the lines whose fields are more than 4
awk 'NF > 4' print every line where the value of the last field is > 4
# IN UNIX ENVIRONMENT: convert DOS newlines (CR
awk '{sub(/\r$/,"")};1' format
awk '{sub(/$/,"\r")};1' # IN UNIX ENVIRONMENT: convert Unix newlines (LF)
awk '{gsub(/^[ \t]+|[ \t]+$/,"")};1' delete BOTH leading and trailing whitespace from each
awk -F ":" '{print $1 | "sort" }'
/etc/passwd print and sort the login names of all users
awk 'NR < 11' print first 10 lines of file (emulates behavior of "head")
awk 'NR>1{exit};1' print first line of file (emulates "head -1")
awk 'END{print}' print the last line of a file (emulates "tail -1")
awk '!($5 == "abc123")' print lines which have less than 5 fields