![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AWK: Multiple patterns per line | Plavixo | UNIX for Dummies Questions & Answers | 1 | 05-05-2008 01:31 PM |
| How to cut multiple patterns from a file? | Vijay06 | Shell Programming and Scripting | 5 | 11-26-2007 05:38 PM |
| Can we give multiple patterns to a sed command??? | kumarsaravana_s | Shell Programming and Scripting | 6 | 03-22-2007 11:19 PM |
| Grep multiple patterns | malaymaru | Shell Programming and Scripting | 4 | 09-24-2005 10:20 PM |
| grep for multiple patterns | tselvanin | UNIX for Dummies Questions & Answers | 1 | 11-12-2003 03:43 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Grep for Multiple patterns
Hi All,
I have a file. I need to find multiple patterns in a row and need those rows to divert to new file. I tried using grep -e / -E / -F options as given in man. But its not working. ==> cat testgrep.txt william,fernandes,xxxxx mark,morsov,yyyy yy=,xx= yyyy=,xxxx== ==> /usr/xpg4/bin/grep -E 'yy xx' testgrep.txt It gives not output. ==> /usr/xpg4/bin/grep -F 'yy xx' testgrep.txt I used pattern file as well ==> cat patterngrep.txt yy\n xx\n /usr/xpg4/bin/grep -e patterngrep.txt testgrep.txt It is not working. Please let me if we have anyother method of doing it. Thanks, |
| Forum Sponsor | ||
|
|
|
|||
|
Are you looking for this info ?
man grep : -f pattern_file Read one or more patterns from the file named by the path name pattern_file. Patterns in pattern_file are terminated by a NEWLINE character. A null pattern can be specified by an empty line in pattern_file. Unless the -E or -F option is also specified, each pattern will be treated as a basic regular expression. You can save all patterns in a file line by line and then grep -f pattern_file Actual_file |
|
|||
|
I have pattern file
==> cat pattern def bc Datafile ==> cat testgrep.txt abc,lmn def,xyz ghi,h jkl I tried this ==> /usr/xpg4/bin/grep -f pattern testgrep.txt abc,lmn ==> /usr/xpg4/bin/grep -E -f pattern testgrep.txt abc,lmn ==> /usr/xpg4/bin/grep -F -f pattern testgrep.txt abc,lmn I am not getting the second line which contains def. |
|
|||
|
Hey Mahendra,
There was some syntax problem. It worked with paatern file Datafile ==> cat testgrep.txt abc,lmn def,xyz ghi,h jkl ==> cat pattern def abc command ==> /usr/xpg4/bin/grep -F -f pattern testgrep.txt abc,lmn def,xyz |
|||
| Google UNIX.COM |