jl66
asked on
How to search multiple patterms in a file with perl?
Have a big text file (t.txt) in windows, which contains multiple phrases to be searched. For example,
AA BB CCBDSA ...
99 22111 33 CC
AC001 004BDXZY CF
DDDASA wwer DDacFD
...
How to print out any lines containing "AC" OR "BD" regardless the case, which are
AA BB CCBDSA ...
AC001 004BDXZY CF
DDDASA wwer DDacFD
Is it possible to use a one-liner? In a real world, the searched patterns are far more than 2, how to use a continue line in perl (one-liner). If only searching one pattern, the following seems working:
perl -ne "print if $_ =~ /\bAC\b/i" t.txt > t.out
AA BB CCBDSA ...
99 22111 33 CC
AC001 004BDXZY CF
DDDASA wwer DDacFD
...
How to print out any lines containing "AC" OR "BD" regardless the case, which are
AA BB CCBDSA ...
AC001 004BDXZY CF
DDDASA wwer DDacFD
Is it possible to use a one-liner? In a real world, the searched patterns are far more than 2, how to use a continue line in perl (one-liner). If only searching one pattern, the following seems working:
perl -ne "print if $_ =~ /\bAC\b/i" t.txt > t.out
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER