![]() |
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 |
| HELP! PERL script to find matched pattern | kimhuat | Shell Programming and Scripting | 1 | 05-12-2008 10:24 AM |
| Script to find file name for non matching pattern | sujoy101 | Shell Programming and Scripting | 5 | 03-31-2008 09:10 AM |
| find and replace a pattern in a file | krishnamaraju | Shell Programming and Scripting | 1 | 08-29-2006 10:02 AM |
| Find script with input pattern file | iguanathompson | Shell Programming and Scripting | 8 | 02-06-2006 06:23 PM |
| how to find the exact pattern from a file? | surjyap | Shell Programming and Scripting | 7 | 12-05-2005 09:00 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
perl - how do i find out if a file doesn't contain a pattern?
how do i check a file for a pattern and perform an action if it doesn't exist?
i know how to search a file for a pattern. you just place it in an array like so. Code:
#!/usr/bin/perl
my $data_file = "file.txt";
open DATA, "$data_file";
my @array_of_data = <DATA>;
if ($_ =~ m/pattern/i) {
print "\nfile contains pattern";
}
close DATA
how do search the whole file for the non-existence of the pattern? hope i've made sense? |
|
||||
|
Perl regular expressions
[^something] matches any character except those that [something] denotes; that is, immediately after the leading “[”, the circumflex “^” means “not” applied to all of the rest [^abc]+ any (nonempty) string which does not contain any of a, b and c (such as defg) ~~~Sanjay~~~ |
|
||||
|
i've figured out a better solution.
i didn't know there was a 'grep' command until i curiously typed into google "perl +grep". i'm very new to perl by the way. Code:
#!/usr/bin/perl
my $data_file = "file.txt";
open CHK_ARRAY, $data_file;
my @chk_array = <CHK_ARRAY>;
close CHK_ARRAY;
if (grep(/pattern/,@chk_array) eq 0) {
print "\npattern not here!";
}
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|