![]() |
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 |
| read list of filenames from text file and remove these files in multiple directories | fxvisions | Shell Programming and Scripting | 5 | 08-07-2008 03:59 PM |
| How can I rename multiple files depending on a string occuring in the filenames? | karman | UNIX for Dummies Questions & Answers | 6 | 05-22-2007 02:29 PM |
| Getting a list of filenames of moved files | chengwei | Shell Programming and Scripting | 3 | 04-23-2007 03:25 AM |
| read list of filenames from text file, archive, and remove | fxvisions | Shell Programming and Scripting | 5 | 03-20-2007 09:56 PM |
| String replace perl script error | MobileUser | Shell Programming and Scripting | 6 | 05-04-2006 09:18 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
perl script to list filenames that do not contain given string
Hi,
I need to write a perl script that should do a search recursively in all the '*.txt' files for the string "ALL -Tcb" and should print only the file names that do not contain this string. |
|
||||
|
Why Perl? It can be done, of course, but it sounds easier in shell.
Code:
find . -type f -name '*.txt' -print | while read file; do grep -l "ALL -Tcb" "$file" >/dev/null && continue echo "$file" done |
|
||||
|
Hmm, this is a Unix forum ...?
Code:
perl -MFile::Find -e 'find(sub {
return 0 unless (m/\.txt$/); # skip file names which don't match this regex
open (F, $File::Find::name) || warn "could not open $File::Find::name: $!\n";
my $match = grep { /ALL -Tcb/ } <F>;
close F;
print "$File::Find::name\n" unless $match;
return ! $match; }, ".")'
The final parameter is the list of directories to traverse; simply "." will traverse the current directory and its subdirectories. Last edited by era; 04-21-2008 at 03:11 AM.. Reason: Skip files which don't match /\.txt$/ |
![]() |
| Bookmarks |
| Tags |
| linux, perl, perl regex, perl shift, regex, shell script, shift, shift perl, ubuntu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|