Count number of lines under each header in a text file using bash shell script -
i can in python or other high level language. interested in doing bash.
here file format:
head-xyz item1 item2 item3 head-abc item8 item5 item6 item9
what print following output:
head-xyz: 3 head-abc: 4
header have specific pattern similar example gave above. items have specific patterns in example above. interested in count of items under each header.
you can use awk
:
awk '/head/{h=$0}{c[h]++}end{for(i in c)print i, c[i]-1}' input.file
Comments
Post a Comment