Skip to content

Instantly share code, notes, and snippets.

@tldrafael
Last active October 5, 2018 20:37
Show Gist options
  • Save tldrafael/24a84377a07406a0e2e6e4406c95480e to your computer and use it in GitHub Desktop.
Save tldrafael/24a84377a07406a0e2e6e4406c95480e to your computer and use it in GitHub Desktop.
Awk tricks
## summary.csv and input_postconnect.csv are dummy files of example.
# Filter examples
## print entire row
awk -F';' '{ if( ($3=="") && (($5~"human")||($5~"machine"))) { print } }' summary.csv
awk -F';' '{ if( ($3~"human") && ($5!~"human") && ($5!="")) { print } }' summary.csv
## print specific column $1
awk -F';' '{ if( ($3~"human") && ($5!~"human") && ($5!="")) { print $1 } }' summary.csv
# Create new column based on ifelse statement
awk -F';' '{ print $4,$2}' OFS=';' input_postconnect.csv | awk -F';' '{ if($2 ~ "human") $(NF+1)="human"; else $(NF+1)="nohuman"; print}' OFS=';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment