Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Sed in perl

by 1nickt (Canon)
on Oct 11, 2018 at 00:40 UTC ( [id://1223841]=note: print w/replies, xml ) Need Help??


in reply to Sed in perl

Hi, no sed, use Perl natively for this! It's what Perl is made for. Open the file, loop through the lines, save the last instance of YYY, print it when you find ABC.

use strict; use warnings; my $last_seen; for my $line ( <DATA> ) { $last_seen = $line if $line =~ /YYY/; print $last_seen if $line =~ /ABC/; } __DATA__ something something YYY first something something YYY second something ABC something
Output:
$ perl ~/monks/1223838.pl YYY second

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Sed in perl
by abhay180 (Sexton) on Oct 11, 2018 at 01:08 UTC
    Thx!!! yes, i can do this. It would be great to understand why the sed is not working though.
      I would
      my $cmd = "tac temp.xx | sed -n '/$mod /,/YYY/ p'| grep XXX"; print "executing: '$cmd'\n"; $hier = `$cmd`; print "result: '$hier'\n";
      to actually see what's going on.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1223841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found