13

Awk to Count Multiple patterns in a huge file

view full story
linux-howto

http://www.unix.com – Hi, I have a file that is 430K lines long. It has records like below |site1|MAP |site2|MAP |site1|MODAL |site2|MAP |site2|MODAL |site2|LINK |site1|LINK My task is to count the number of time MAP, MODAL, LINK occurs for a single site and write new records like below to a new file SiteName MAP MODAL LINK -------------------------- site1 | 1 | 1 | 1 site2 | 2 | 1 | 1 I have accomplished this using grep by doing countmap=`grep $SITEID $FILENAME | grep MAP | wc -l` countmodal=`grep $SITEID $FILENAME | grep MODAL | wc -l` countlink=`grep $SITE (HowTos)