12-09-2004
Quote:
find the number of occurence of a specified pattern in a file
grep -c <pattern> <filename>
:-0
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it.
similar to
grep 'pattern' filename | tail -1 in UNIX
Ex: I want to display the line starting with "cool" and which is a last occurence
adadfadafadf
adfadadf
cool dfadfadfadfara... (4 Replies)
Discussion started by: ammu
4 Replies
2. Shell Programming and Scripting
I would like to use sed to replace one occurence of a pattern in a file. When I use the s/// command it replaces all occurences of the pattern in the file. Should I be using something other than sed?
Thanks (6 Replies)
Discussion started by: ss9u
6 Replies
3. Shell Programming and Scripting
hi,
is it possible to find the number of occurences of a pattern between two paranthesis.
for e.g
i have a file as below.
>>{
>>hi
>>GoodMorning
>>how are you?
>>}
>>is it good,
>>tell me yes, if it is good
In the above file, its clear the occurence of word "Good"... (17 Replies)
Discussion started by: divak
17 Replies
4. Shell Programming and Scripting
Hello all,
I have a input file like this.
input file
---------------
abc ab001 + ab002 zca
acb ab006 + ab007 caz
cba ab003 + ab004 zca
bac ab004 - ab005 zac
bca ab002 - ab003 cza
cba ab005 + ab006 acz
cba ab005 ... (5 Replies)
Discussion started by: admax
5 Replies
5. UNIX for Dummies Questions & Answers
Hi
I want to search for a specific pattern in file
Say
ABC;HELLO_UNIX_WORLD;PQR
ABC;HELLO_UNIX_WORLD_IS_NOT_ENOUGH;XYZ
ABC;HELLO_UNIX_FORUM;LMN
Pattern to search is : "HELLO_UNIX_*****" and not "HELLO_UNIX_***_***_"
I mean after "HELLO_UNIX" there can only be one word.In this case... (2 Replies)
Discussion started by: dashing201
2 Replies
6. Linux
Hi
I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line.
Eg:
#this is example
#/root/xyz:Old_Pattern
/root/xyz:Old_Pattern
/root/xyz:Old_Pattern
... (10 Replies)
Discussion started by: Stoner008
10 Replies
7. Shell Programming and Scripting
Hi,
Do anybody know how to use awk to count the pattern at specific column?
Input file
M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a
.
.
Output file
M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a 3
.
.
I plan to count how many "miR" in column 3... (2 Replies)
Discussion started by: cpp_beginner
2 Replies
8. UNIX for Dummies Questions & Answers
I have a large file and many lines are duplicated. I'm trying to delete lines with every second occurrence of a pattern. Did tried searching similar question but no luck.
I can delete all lines matching pattern with :g/pattern/d but don't want to lose data.
Sample pattern to delete... (6 Replies)
Discussion started by: homer4all
6 Replies
9. Shell Programming and Scripting
My data
20161220 20:30:01 MODE 1 TEST 1 SOURCE 1 SET 1
20161220 20:30:02 MODE 1 TEST 2 SOURCE 1 SET 1
20161220 20:30:02 MODE 1 TEST 3 SOURCE 1 SET 1
20161220 20:30:02 MODE 1 TEST 1 SOURCE 2 SET 1
20161220 20:30:04 MODE 1 TEST 1 SOURCE 1 SET 1 MODE 1 TEST 2 SOURCE 2 SET 1
20161220 20:30:02... (7 Replies)
Discussion started by: migurus
7 Replies
10. Shell Programming and Scripting
Hello.
Here is a file contents :
declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern
=I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '='
Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies
INSTR(3) MBK UTILITY FUNCTIONS INSTR(3)
NAME
instr - find an occurence of a string in a string, starting at a specified character.
ORIGIN
This software belongs to the ALLIANCE CAD SYSTEM developed by the ASIM team at LIP6 laboratory of Universite Pierre et Marie CURIE, in
Paris, France.
Web : http://asim.lip6.fr/recherche/alliance/
E-mail : alliance-users@asim.lip6.fr
SYNOPSYS
#include "mut.h"
char *instr(s, find, from)
char *s, *find, from;
PARAMETERS
s Pointer to the string to be searched for the pattern
find Pointer to the string to be found, the pattern
from Character to be searched backwards before searching for the pattern
DESCRIPTION
instr searches the first occurence of the string find in the string s, starting its search at the last occurence of the from character in
the string s.
If either s or find is NULL, the function returns NULL. If from is (char)0, the pattern is searched from the begining of s.
This quite exotic behaviour is useful to search the occurence of a name in a string resulting from a flatten, when only a terminal object
name is to be taken into account.
RETURN VALUES
instr return NULL either if the pattern find is not present in the searched string s, or if one at least of these two string are NULL. If
the pattern is found, a value different from NULL is returned.
EXAMPLE
#include "mut.h"
/* check for the pattern 'ck' anywhere in the string */
#define contains_ck(name)instr(name, "ck", ' ')
/* check for the pattern 'ck' in the signal name, not instance ones */
#define isclock(ptsig) instr(getsigname(ptsig), "ck", SEPAR)
SEE ALSO
mbk(1), isvdd(3), isvss(3).
BUG REPORT
This tool is under development at the ASIM department of the LIP6 laboratory.
We need your feedback to improve documentation and tools.
ASIM
/LIP6 October 1, 1997 INSTR(3)