![]() |
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 |
| AWK: Multiple patterns per line | Plavixo | UNIX for Dummies Questions & Answers | 1 | 05-05-2008 04:31 PM |
| Multiple line match using sed | SiftinDotCom | Shell Programming and Scripting | 15 | 03-28-2008 02:12 PM |
| read and match multiple lines in perl | zx1106 | Shell Programming and Scripting | 5 | 03-14-2008 10:21 PM |
| Multiple file processing - 1st line only to process - search/match substring | toneatlondon | Shell Programming and Scripting | 2 | 01-02-2008 09:20 PM |
| How to parameterize multiple search patterns and generate a new file | augustinep | UNIX for Dummies Questions & Answers | 6 | 07-30-2003 08:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Perl: Match a line with multiple search patterns
Hi
I'm not very good with the serach patterns and I'd need a sample how to find a line that has multiple patterns. Say I want to find a line that has "abd", "123" and "QWERTY" and there can be any characters or numbers between the serach patterns, I have a file that has thousands of lines and each of them can contain one or two of above patterns. What I want is to print out a line that has all those 3 search patterns. Thanks, //Juha |
|
||||
|
It is not clear if you need to check for all the patterns or any of the patterns:
All of them: Code:
if (/123/ && /abd/ && /QWERTY/) {
found all patterns
}
any of them: Code:
if (/123/ || /abd/ || /QWERTY/) {
found one or more patterns
}
|
|
||||
|
Quote:
|
|
||||
|
Yes, but the next sentence makes that ambiguous (to me anyway):
Quote:
|
|
||||
|
ok.. Let me clarify a little:
Originally I wanted to print a line only if ALL the patterns can be found from that line, so this was ok: Code:
if (/123/ && /abd/ && /QWERTY/) {
found all patterns
}
I'd like to print the line only if I can find "123" and abc", but not "efg": I thought maybe I could use: Code:
if (/123/ && /abc/ !& /efg/) {
found all patterns
}
Thanks.. and sorry for being a bit unclear.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|