Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
I am in the process of converting a lot of shell scripts to Perl. I am having a problem with the following:
#!/usr/bin/ksh GrepList=`sed '/^ *$/d;/^#/d' traplist.in 2>/dev/null` grep -ilF "$GrepList" out/do* 2>/dev/null | xargs -i mv {} ./capture 2 +>/dev/null
This isn't the entire script, but it is in a continual loop.
The mv is in a race condition that is beyond my control and the GrepList changes over time.
Some of the limitations of the shell script implementation are:
1. The item in the GrepList that matched isn't recorded
2. The grep fails if the string is wrapped (imbedded) newline
I came up with the following (with help from the CB) as a start (code doesn't exactly match)
#!/usr/bin/perl my @checklist; my @testfile; my $rulenames; open (FILE,"filename"); while (<FILE>) { next if ( $_ =~ /^ *$/ || $_ =~ /^#/ ); push @checklist , $_; } chomp @checklist; close (FILE); my $GrepList = join '|', map "($_)", @checklist; @ARGV = <*>; if (@ARGV) { undef $/; while (<>) { $_ =~ s/\n//; next unless ($_ =~ /$GrepList/i); print "$ARGV : $+\n"; } }
The final product will store the time stamp of the traplist file and only update on change and fix the obvious errors, but I am more concerned with the raw functionality.
What I am trying to accomplish is the following:
What I can't do is:
I originally envisioned what I do when I do a word search. You scan using your finger until you come across a letter that starts a word you are looking for. You follow it until you get a match or until you realize it is a dead end. If it is a dead end, you keep on going having forgot everything that came before.
Unfortunately, I don't believe there is a way to tell RegEx to start paying attention on a partial match.
Any ideas?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Shell Script Woes (tye's try)
by tye (Sage) on Jan 02, 2003 at 22:59 UTC | |
by Limbic~Region (Chancellor) on Jan 09, 2003 at 20:14 UTC | |
by tye (Sage) on Jan 09, 2003 at 21:30 UTC | |
by Limbic~Region (Chancellor) on Jan 10, 2003 at 23:14 UTC | |
Re: Shell Script Woes
by traveler (Parson) on Jan 02, 2003 at 23:00 UTC | |
Re: Shell Script Woes
by runrig (Abbot) on Jan 02, 2003 at 23:57 UTC |