Skip to content

Instantly share code, notes, and snippets.

@sambos
Created May 3, 2018 19:00
Show Gist options
  • Save sambos/5801c5026938cd2860ff04531fa1191d to your computer and use it in GitHub Desktop.
Save sambos/5801c5026938cd2860ff04531fa1191d to your computer and use it in GitHub Desktop.
grep awk commands
regex101.com
Capture tomcat log
2013-12-05 21:39:15,813 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Success!
/^([0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9:]{1,},[0-9]{3})\s\[([a-zA-Z]+)\]\s([a-zA-Z]{1,})\s+(.*)$/g
Extracting json fields from a file
grep -Po '"text":.*?[^\\]",' <file>
grep -Po '"TRANS_ID":.*?[^\\]",' <file>
And … doing a word count..
grep -Po '"TYPE":"jdbc",' temp | wc -l
extraction "key":"value" from json
$ grep "string" <file-name> | awk -F "," '{print $1}' | sort
$ grep -Po '"KEY":.*?[^\\]",' *-file.json | awk -F ":" '{print $3}' | uniq | wc -l
cat trx082516-1000-1200-std.json | grep -Po '"correlationId":.*?[^\\]",' | awk -F "\"" '{print $4}' | sort -nr | uniq -c > id.log
cat id.log | awk -F " " '$1 > 1000 {print $1}' | sort
cat part-m-00000 | awk -F "," '{print $13}' | sort -nr | uniq -c | awk -F " " '$1 > 100' | sort
grep -Po '"m_steps":.*?[^\\]",' | awk -F "\"" '{print $4}' | sort -nr | uniq -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment