awk '{ for (i=1;i<=NF;i++) if ( $i == "word" ) count++ } END{print count}' filename
This will print the count of the occurance of a pattern "word" in a file.
This will print the count of the occurance of a pattern "word" in a file.
UNIX/Linux problem solving blog, Good for beginners and experts. UNIX interview preparation guide. Top Unix interview questions and answers. awk,sed,vi shell,perl solutions of Unix problems.
No comments:
Post a Comment