Skip to content

Instantly share code, notes, and snippets.

@PankajWorks
Created October 4, 2016 14:01
Show Gist options
  • Save PankajWorks/b8b0c3f596cb8f399f309944603078e3 to your computer and use it in GitHub Desktop.
Save PankajWorks/b8b0c3f596cb8f399f309944603078e3 to your computer and use it in GitHub Desktop.
echo 'this is a test' | awk '{print $NF}' #print last column
awk '{print $1, $(NF-2) }' access_log
awk '{print NR ") " $1 " -> " $(NF-2)}' access_log #NR prints the row number
awk '{print $2}' access_log | awk 'BEGIN{FS=":"}{print $1}' #splits along ':'
awk '{print $2}' logs.txt | awk 'BEGIN{FS=":"}{print $1}' | sed 's/\[//'
awk '{if ($(NF-2) == "200") {print $0}}' # conditional
awk '{a+=$(NF-2)}END{print "Total:", a}' logs.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment