Skip to content

Instantly share code, notes, and snippets.

@mk-qi
Last active May 13, 2022 23:25
Show Gist options
  • Save mk-qi/6672485 to your computer and use it in GitHub Desktop.
Save mk-qi/6672485 to your computer and use it in GitHub Desktop.
text_parser.awk
#!/usr/bin/awk -f
BEGIN {
ARGV[1] = "/Users/mk/code/awk/tmp.txt";
ARGC = 2;
FS=","; OFS="";
FORMAT="%-30s%-10s%s\n";
printf (FORMAT, "pre_key","counts","totalsize");
printf (FORMAT, "=======","======","=========")
}
{
split($3,a,":");key=a[1]":"a[2];n[key]++; size[key]+=$4;
}
END {
{for(i in n){printf(FORMAT, i, n[i],size[i])}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment