![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to find a count of a word within a file | bd_joy | Shell Programming and Scripting | 9 | 07-14-2008 06:29 AM |
| Count strings on single line? | cs03dmj | Shell Programming and Scripting | 6 | 05-22-2008 01:09 AM |
| Problem to search multiple strings | sudhish | Shell Programming and Scripting | 2 | 10-25-2007 11:00 AM |
| To find the count of records from tables present inside a file. | navojit dutta | Shell Programming and Scripting | 1 | 08-29-2007 08:04 AM |
| find multiple file types and tar | manthasirisha | Shell Programming and Scripting | 9 | 03-21-2006 09:37 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
I need to find the line count of multiple strings in a particular file. The strings are as follows:
bmgcc bmgccftp bsmsftp bulkftp cctuneftp crbtftp crmpos cso gujhr I am doing manual grep for each of the string to find the line count. The command i am using right now is: grep mark push.cdr.20071123.144325 | wc -l Is there any better way of doing this. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
awk '{ arr[$0]++ }END{for ( i in arr ) { print i, arr[i] } }' file
|
|
#3
|
||||
|
||||
|
Hi, salaathi.
You didn't say anything about the input file. Here's a script that allows a general input file. The file is broken apart, sorted, counted, and searched according to your list: Code:
#!/usr/bin/env sh # @(#) s1 Demonstrate counting strings in arbitrary text file. set -o nounset echo debug=":" debug="echo" ## Use local command version for the commands in this demonstration. echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version bash tr sort uniq grep echo FILE=data1 STR=strings1 echo " Input file:" cat data1 echo echo " Results of carving, sorting, counting, searching pipeline:" tr ' ' '\n' <$FILE | sort | uniq -c | grep -f $STR exit 0 Code:
% ./s1
(Versions displayed with local utility "version")
GNU bash 2.05b.0
tr (coreutils) 5.2.1
sort (coreutils) 5.2.1
uniq (coreutils) 5.2.1
grep (GNU grep) 2.5.1
Input file:
Ekinsud myel irradiate persona chufte spumsuds diagnosable
esplanade dregh. Minoan victor ighent intellectual otem
ensodsil. Swibsik exclusion cereal transpacific loin florican
flagellate charm snick. bulkftp cctuneftp cso bulkftp Adoptive
launch marrow gridiron heredity sulfa cultivable mutate sterile
partisan chamois. Testamentary miraculous otsonsev silverware
cso bulkftp cctuneftpd meridian? Scev quarterback hare hood
spectral adrift bourbon bulkftp cctuneftp cso cctuneftp
employed. Doctrine win benevolent ethic plumbago trailhead men
Mbabane diagnoses incorrect Claire. Assess yoke summate variate
Freddy fluid Rwanda confine Albany southbound origin. Keel
Chapman prep blueback thirteen Halpern. Piss affricate AZ
fanfold Lebanese rollick topocentric butte honorific pretext cso
cso bedevil? Ers douce Wilhelm deniable seater scherzo.
Results of carving, sorting, counting, searching pipeline:
4 bulkftp
3 cctuneftp
1 cctuneftpd
5 cso
|
|
#4
|
||||
|
||||
|
The same i tried with some for statement.
It's working fine. Thanks for your response. FILENAME= string= echo "enter file name :\c" read FILENAME echo "enter string to find seperated by space:\c" read string for rc in $string do grep $rc $FILENAME | wc -l done |
||||
| Google The UNIX and Linux Forums |