![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| First occurence of character in a file | dhanamurthy | Shell Programming and Scripting | 6 | 05-12-2008 09:56 PM |
| Perl onliner to search the last line with an occurence of a pattern | ammu | Shell Programming and Scripting | 4 | 01-30-2008 09:09 PM |
| Count the number of occurence of perticular word from file | rinku | Shell Programming and Scripting | 40 | 08-10-2007 04:33 PM |
| How to search a pattern inside a zipped file ie (.gz file) with out unzipping it | senraj01 | Shell Programming and Scripting | 2 | 04-26-2006 01:32 AM |
| Search file for pattern and grab some lines before pattern | frustrated1 | Shell Programming and Scripting | 2 | 12-22-2005 11:41 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Pattern occurence in a file
How can we find the number of occurence of a specified pattern in a file?
This command would be a part of a shell script. |
| Forum Sponsor | ||
|
|
|
|||
|
Something like this maybe:
#!/bin/bash SEARCHSTRING="foo" sed "s/${SEARCHSTRING}/${SEARCHSTRING}\n/g" infile | \ grep ${SEARCHSTRING} | wc -l Did 2 quick tries. One on a text file an d the second on a script with a more complex searchstring. Both worked. Hope this helps. |