![]() |
|
|
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 |
| Extracting a string from one file and searching the same string in other files | mohancrr | Shell Programming and Scripting | 1 | 09-19-2007 04:17 AM |
| Perl: searching for a string in a file... | pondlife | Shell Programming and Scripting | 4 | 09-17-2007 08:35 AM |
| Hi! Searching for a text string in UNIX | skwadim | UNIX for Dummies Questions & Answers | 1 | 12-22-2006 01:13 PM |
| Searching directory for file that contains some text. | LordJezo | UNIX for Dummies Questions & Answers | 4 | 04-04-2006 09:58 PM |
| Help with searching a text file | thekid2 | Shell Programming and Scripting | 6 | 01-02-2004 02:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Hi. Here is a quickly-written possibility: Code:
#!/usr/bin/perl
# @(#) p2 Demonstrate matching across line boundaries.
use warnings;
use strict;
my ($debug);
$debug = 0;
$debug = 1;
my $file;
for $file (@ARGV) {
print "\n -----\n";
my $lines = slurp($file);
print " File contains:\n$lines";
print "\n";
if ( $lines =~ /United.*Champions.*Ronaldo/xms ) {
print " Hit!\n";
}
else {
print " Oh, a miss!\n";
}
}
sub slurp {
# Best practices, p213 for a file.
my ($file) = shift;
my ($f);
open( $f, "<", $file ) || die " Can't open file $file, quitting.\n";
my $scalar = do { local $/; <$f> };
return $scalar;
}
exit(0);
Producing output for a bad dataset and a good dataset: Code:
% ./p2 data1 data2 ----- File contains: United Champions Liverpool Losers Torres Oh, a miss! ----- File contains: United Champions Ronaldo Liverpool Losers Torres Hit! See perl documentation for details ... cheers, drl |
![]() |
| Bookmarks |
| Tags |
| linux, perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|