Search Mulitiple String pattern in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search Mulitiple String pattern in a file
# 1  
Old 11-23-2007
Search Mulitiple String pattern in a file

Hi,

I need to search for a multiple string pattern(5 key words) in a file(similar to a flat file) ,and i need to store the output in a another file .

In that file we may have mutiple occurrences of the key words.and i need only the unique.

kindly help out.


Thanks,
Mohana Krishnan
# 2  
Old 11-23-2007
Quote:
Originally Posted by krishnan_6015@y
Hi,

I need to search for a multiple string pattern(5 key words) in a file(similar to a flat file) ,and i need to store the output in a another file .

In that file we may have mutiple occurrences of the key words.and i need only the unique.

kindly help out.


Thanks,
Mohana Krishnan

Hi Mohana Krishnan,

I don't understand this line. Can you explain it.

In that file we may have mutiple occurrences of the key words.and i need only the unique.

To search multiple patterns in a file u can use grep with -e option.

grep -e pattern1 -e pattern2 -e pattern3 filename > newfile.

Regards,
Chella
# 3  
Old 11-23-2007
Or 'egrep / grep -E':
Code:
egrep 'term1|term2|term3'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies

2. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

3. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

4. 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

5. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

6. Shell Programming and Scripting

Awk search for string pattern in delimited file

I've got a semicolon delimited file. I would like to search for fields that match a pattern, and not hardcoded eg "mth". *th=something If the delimited field fulfills this condition, eg. mth=value I would like to print out both key and value for some number comparison. eg. if value > "12"... (5 Replies)
Discussion started by: alienated
5 Replies

7. UNIX for Dummies Questions & Answers

How to search for a pattern a string?

Hi all, I'm new in UNIX , so how to check if stringA is present within stringB ? Something similar to INSTR function in pl sql... Thanks a lot. (12 Replies)
Discussion started by: Leo_NN
12 Replies

8. UNIX for Dummies Questions & Answers

search pattern in a string and rename

Hi All, I have a string assigned to a variable. the string will be a filename. Something like below: file=testfile.dat.20009080_{arc}_2004809090 I need to check if the filename has a pattern like "_{arc}_" and if so I have to rename the file like below mv... (6 Replies)
Discussion started by: deepakgang
6 Replies

9. Shell Programming and Scripting

Advance string pattern search Please

Here is my problem.. 1. I want to search all those files with file name starting AJ128**** (in all the sub directories also) 2. I want to search for the follwoing type of string line beging with string - 'AK*any_1_char*any_2_char*510' 3. I need to display list of file names... (2 Replies)
Discussion started by: sainj
2 Replies
Login or Register to Ask a Question