Filter by several conditions
Print lines where field 2 is over 500 and field 5 is POST
awk '$2 > 500 && $5 == "POST"' access.log
- tool
- awk15 commands
More awk commands
-
awk '{printf "%-20s %5d\n", $1, $2}' data.txtAlign output in fixed-width columns with printf
-
awk -f transform.awk input.txtLoad the awk program from a separate file
-
awk '{gsub(/foo/, "bar"); print}' input.txt > tmp && mv tmp input.txtReplace all matches and write the result back to the same file
-
gawk -v FPAT='([^,]+)|("[^"]+")' '{print $2}' data.csvParse quoted CSV fields correctly with FPAT in gawk
-
awk 'BEGIN{print "Start"} {lines++} END{print lines" lines processed"}' file.txtRun code before and after all lines are processed