string - Multilevel parsing using shell command -
i have file in following format
///// name 1 start_occurrence: occurrence 1 occurrence 2 /// name 2 start_occurance: occurrence 1 occurrence 2 /// name 3 start_occurrence: occurrence 1 occurrence 2 occurrence 3
all need make count of number of occurrences each name , save them in csv file. can using combination of shell commands? yes can programmatically, looking bunch of shell commands in pipe lined fashion.
"names
" can anything. names not come pattern. catch line after ///
name. occurrence
not have number it, anyline starts occurrence
or have occurrence
subject of interest.
awk 'c=="thisisname"{b=$0;c="";}$1=="///"{c="thisisname"}$0~/\<occurrence\>/{a[b]+=1;}end{for (i in a){print i" "a[i]}}' your_file_here
explain:
if match name start condition ($1=="///"), mark c thisisname. if name line (c=="thisisname"), mark name line b, , mark c name part ended(c=""). if match occurrence condition ($0~/\<occurrence\>/), make a[b] += 1. use map remark occurrence time of each name.
awk use eres, $0~/eres/ means $0 match regex. '\<' , '>' means '\b' in pres
Comments
Post a Comment