Thursday, July 30, 2009

Unix problem?

Hye guys


I have two problems in unix.





1. The first problem is that I wanna search for a word in a text file and then print it's count i.e how many times it occurs in that file.Now I tried this





grep "searchword" filename | wc -l





it works well but it counts the lines where the search word appears.If the word appears twice in a line,it still counts it as one.So pls help.I want the word count,not the number of lines matching the pattern.





2.Second problem is that I need to count number of symbols (* % $ etc) in a file.How can I do that??





Thanks in advance.

Unix problem?
for the first one you can use


grep -o "searchword" filename| wc -l (or) wc -w





for the second one also you can use the same command with wc -c


if you have to count special characters like \ you have to use \\.i.e use a \ before a special character.


No comments:

Post a Comment