Hi all
I currently use the following in shell.
#!/bin/sh
while read LINE
do
perl -i -ne "$/ = ''; print if !m'Using archive: ${LINE}'ms;" "datafile"
done < "listfile"
NOTE the single quote delimiters in the expression. It's highly likely the 'LINE' may very well have characters in it that perl will try to interpolate. For example the '@'... See sample data.
I would like to reduce the overhead of the multi perl calls and do both loops in one perl call from within a shell.
So Inspired by this thread: Removing Lines if value exist in first file
And this bit of code from that thread:
my @a, %exclude;
my $file = shift;
open(EXCLUDE_LIST, "< $file") or die;
chomp( @a=<EXCLUDE_LIST> );
close(EXCLUDE_LIST);
@exclude{@a}=@a;
while (<>) {
print unless exists $exclude{ (split(/,/))[3] };
}
I have been attempting to hack into submission without success!
HELP!
I like the idea of the hash, however that is way above my head and after many hours of pawing over this site and the perl man pages I have yet to even come close to figuring out how to use it!
If I understand the above with the use of the hash, that would limit the loop to one iteration for multiple matches!
Correct or Incorrect??
And if needed, The following is sample datafile, listfile and results.
Sample datafile: (first line is blank, last line is not)
Backup started: Sat Aug 22 05:15:00 EDT 2009, MyBackup v3.0.8
Using archive: /mnt/Raid/test/Backup_20090822@051500.tbz
Removed archive: /mnt/Raid/test/Backup_20090820@051500.tbz
Backup completed: 293,437,440 bytes in 131 seconds at 05:17:11 EDT
Backup started: Sun Aug 23 05:15:00 EDT 2009, MyBackup v3.0.8
Using archive: /mnt/Raid/test/Backup_20090823@051500.tbz
Removed archive: /mnt/Raid/test/Backup_20090821@051500.tbz
Backup completed: 224,477,184 bytes in 100 seconds at 05:16:40 EDT
Backup started: Mon Aug 24 05:15:00 EDT 2009, MyBackup v3.1.0
Using archive: /mnt/Raid/test/Backup_20090824@051500.tbz
Removed archive: /mnt/Raid/test/Backup_20090822@051500.tbz
Backup completed: 224,307,734 bytes in 99 seconds at 05:16:39 EDT
Backup started: Tue Aug 25 05:15:00 EDT 2009, MyBackup v3.1.0
Using archive: /mnt/Raid/test/Backup_20090825@051500.tbz
Removed archive: /mnt/Raid/test/Backup_20090823@051500.tbz
Backup completed: 237,993,204 bytes in 104 seconds at 05:16:44 EDT
Sample listfile: No blanks
/mnt/Raid/test/Backup_20090823@051500.tbz
/mnt/Raid/test/Backup_20090825@051500.tbz
Target Results: (first line is blank, last line is not)
Backup started: Sat Aug 22 05:15:00 EDT 2009, MyBackup v3.0.8
Using archive: /mnt/Raid/test/Backup_20090822@051500.tbz
Removed archive: /mnt/Raid/test/Backup_20090820@051500.tbz
Backup completed: 293,437,440 bytes in 131 seconds at 05:17:11 EDT
Backup started: Mon Aug 24 05:15:00 EDT 2009, MyBackup v3.1.0
Using archive: /mnt/Raid/test/Backup_20090824@051500.tbz
Removed archive: /mnt/Raid/test/Backup_20090822@051500.tbz
Backup completed: 224,307,734 bytes in 99 seconds at 05:16:39 EDT
Thanks
-Enjoy
fh : )_~