i want to count the "ing" in this line using awk when am going to home. it start to raining, so i am running toward home
i want print how many times "ing" came in the line using awk
it should print 3
awk's gsub command returns the number of times "ing" was replaced: count=gsub("ing","", $0) # count should equal 3
thank you
If the pattern you are looking for is in multiple lines in the same file, then you just can use the following (slightly modified version of nails): cat <file name> | awk ' { count=gsub("ing", "", $0); if (count==1) TOTAL+=1; } END { print TOTAL } '
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |