like everyone else, I'm not 100% sure I understand what you want. But if it's just to print out the lines between a start and a stop regexp, wouldn't this do the trick?
perl -ne 'print if /start/ .. /end/' *.html
Note that this will not allow /start/ and /end/ to be on the same line. If you want that as an option, you need to replace the .. operator with ....
See man perlop.
-- Dan | [reply] [d/l] [select] |
Like everyone else, I'm not sure I understand the question.
But I think what you mean is "I want to start printing when I see regex 1, and stop printing when I see regex 2"... (Edit: Aha, looking at your 2nd post, that does seem to be what you want)
If so, here goes:
perl -i.bak -ne'if(/whateverStartRegexIs/){$print{$ARGV}=1} if(/whatev
+erEndRegexIs/){$print{$ARGV}=0;} print if $print{$ARGV};' *.html
Now, if start regex and end regex match on the same line, this won't print at all. You have to figure out if that's what you want or not.
Also, if you have start...end...start...end in the same file, this will print two sets of lines for a given file. If that's not what you want, you could add a %done hash keyed on $ARGV as well...
Hope this helps!
--
Mike | [reply] [d/l] |
Um, I have tried this fella...
perl -pi.bak -e "/end_reg/ && print && last; /start_reg/ && $inside++;
+ next unless inside;" *.html
but it doesn't output anything! Any ideas? | [reply] [d/l] |
perhaps I'm reading this too simply, and you mean something more complex by 'between two regexes', but it sounds like you just want:
perl -pi.bak -e "s/start(.*?)stop/$1/s" *.html
where 'start' and 'stop' are the opening and closing matches, and with a g modifier as well if you want to replace more than once in each file.
update: hold on, that's stupid. sorry. you want to replace the whole file with the match, don't you, or capture that text somewhere else? d'uh. please ignore.
| [reply] [d/l] |
Thankyou all,
This fella is great and exactly what I'm after since the start and end regexes appear only once per file as a nice set and never appear on the same line...
perl -ne 'print if /start/ .. /end/' *.html
My problem is now due to my WinNT shell (CMD.exe) not being able to read the quotes and deal with the glob!
sigh! | [reply] [d/l] |
perl -ne "print if /start/ .. /end/" *.html
works. I'm not sure how you escape a double quote on the command line of cmd.exe, so I use qq(\n) whenever I need to embed a newline...
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [d/l] [select] |
Aw! I get...
C:\temp\>perl -n -e "print if /start/ .. /end/" *.html
Can't open *.html: Invalid argument.
When run under CMD.exe -- I'm not sure if it's perl.exe or CMD.exe complaining here. :(
Msemtd.
| [reply] |
| [reply] |