Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Search and Count Occurrences of Pattern in a File Post 302326270 by BubbaJoe on Wednesday 17th of June 2009 01:06:42 PM
Old 06-17-2009
This might work for you.

Code:
 
srchword=$1;
srchfile=$2;
ctr=`grep -io $srchword $srchfile| wc -l`


Last edited by BubbaJoe; 06-17-2009 at 02:14 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pattern search and count

i want to search a word in a file and find the count of occurences even if pattern occures twice in a same line. for example file has the following content. yes no no nooo yees no yes if I search for "no" it should give count as 4 Pls help. Thanks (9 Replies)
Discussion started by: RahulJoshi
9 Replies

2. Shell Programming and Scripting

Count the number of occurrences of a pattern between each occurrence of a different pattern

I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'. Here's a portion of the text I'm trying to parse: lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb registrations: key 4156 4353 0000 0000 ... (3 Replies)
Discussion started by: slipstream
3 Replies

3. Shell Programming and Scripting

Pattern search and count

Hi all, I need to search the database log find out the most frequently used tables for a certain period of time. The search pattern is : the database.table so, i need to look for ABCD.* in the entire log and then need the top ten tables. I thought of using awk, search for the pattern ... (7 Replies)
Discussion started by: ysvsr1
7 Replies

4. Shell Programming and Scripting

How to search number of occurrences of a particular string in a file through vi editor?

i have one file, i am doing 'vi Filename' now i want to search for particular string and i want to know how many times that string occurs in whole file (5 Replies)
Discussion started by: sheelsadan
5 Replies

5. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

6. Shell Programming and Scripting

Speed : awk command to count the occurrences of fields from one file present in the other file

Hi, file1.txt AAA BBB CCC DDD file2.txt abc|AAA|AAAabcbcs|fnwufnq bca|nwruqf|AAA|fwfwwefwef fmimwe|BBB|fnqwufw|wufbqw wcdbi|CCC|wefnwin|wfwwf DDD|wabvfav|wqef|fwbwqfwfe i need the count of rows of file1.txt present in the file2.txt required output: AAA 2 (10 Replies)
Discussion started by: mdkm
10 Replies

7. Shell Programming and Scripting

Identify file pattern, take count of pattern, then act

Guys - Need your ideas on a section of code to finish something up. To make a long story short, I'm parsing a print output file that goes to pre-printed forms. I'm intercepting it, parsing it, formatting it, cutting it up into individual pages, grabbing the text I want in zones, building an... (3 Replies)
Discussion started by: ampsys
3 Replies

8. Shell Programming and Scripting

Count occurrences in first column

input amex-11 10 abc amex-11 20 bcn amed-12 1 abc I tried something like this. awk '{h++}; END { for(k in h) print k, h }' rm1 output amex-11 1 10 abc amex-11 1 20 bcn amed-12 2 1 abc Note: The second column represents the occurrences. amex-11 is first one and amed-12 is the... (5 Replies)
Discussion started by: quincyjones
5 Replies

9. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies
copt(1) 							z88 Development Kit							   copt(1)

NAME
copt - peephole optimizer SYSNOPIS
copt file ... DESCRIPTION
copt is a general-purpose peephole optimizer. It reads code from its standard input and writes an improved version to its standard output. copy reads the named files for its optimizations, which are encoded as follows: <pattern for input line 1> <pattern for input line 2> ... <pattern for input line n> = <pattern for output line 1> <pattern for output line 2> ... <pattern for output line m> <blank line> Pattern matching uses literal string comparison, with one exception: ``%%'' matches the ``%'' character, and ``%'' followed by a digit matches everything up to the next occurrence of the next pattern character, though all occurrences of %n must denote the same string. For example, the pattern ``%1=%1.'' matches exactly those strings that begin with a string X, followed by a ``='' (the first), followed by a second occurrence of X, followed by a period. In this way, the input/output pattern mov $%1,r%2 mov *r%2,r%2 = mov %1,r%2 commands copt to replace runs like mov $_a,r3 mov *r3,r3 with mov _a,r3 Note that a tab or newline can terminate a %n variable. copt compares each run of input patterns with the current input instruction and its predecessors. If no match is found, it advances to the next input instruction and tries again. Otherwise, it replaces the input instructions with the corresponding output patterns, pattern vari- ables instantiated,and resumes its search with the first instruction of the replacement. copt matches input patterns in reverse order to cascade optimizations without backing up. BUGS
Errors in optimization files are always possible. SEE ALSO
z88dk(1), z88dk-zcc(1), z88dk-z80asm(1), z88dk-appmake(1), z88dk-copt(1). AUTHOR
z88dk was written by Dominic Morris <dom@z88dk.org>, and others. 01 December 2009 copt(1)
All times are GMT -4. The time now is 04:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy