![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep all records in a file and get a word count -perl | meghana | Shell Programming and Scripting | 4 | 02-13-2008 10:06 PM |
| find a word in a file, and change a word beneath it ?? | vikas027 | Shell Programming and Scripting | 2 | 02-13-2008 04:23 PM |
| To find multiple strings count in a file | salaathi | Linux | 3 | 11-28-2007 06:31 AM |
| Count the number of occurence of perticular word from file | rinku | Shell Programming and Scripting | 40 | 08-10-2007 07:33 PM |
| how to find a word repeated in a file | gurukottur | UNIX for Dummies Questions & Answers | 4 | 08-24-2006 04:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to find a count of a word within a file
Hello,
I'm looking for a wait to count the number of occurrences of a certain string of characters within a file. The file that I trying to parce has segments within the file that have a header and footer to each segment and I'm trying to do a count of the header string and compare it to a count of the footer string to verify the integrity of the file. Example file: HEADER misc text and numeric values FOOTER HEADER more misc info FOOTER HEADER etc etc FOOTER There are no carriage returns within the file, and it's about 50 to 60MB text file so the process needs to be somewhat efficient as a short processing timeframe is required. I've done several searches and tried using wc, tr, and sort is a variety of different ways but I'm no closer to finding a solution. I'm a novice to the use of utilities like sed or awk, but ideas using them are welcome. Other general info: I use ksh on AIX 5.3. Thanks for any help! ![]() |
|
|||||
|
Code:
$ echo 'HEADER misc text and numeric values FOOTER HEADER more misc info FOOTER HEADER etc etc FOOTER' | nawk -F'(HEADER)|(FOOTER)' '{print "header+footer-> " NF-1}'
header+footer-> 6
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|