Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: match a word and delete last line

by ArifS (Beadle)
on May 23, 2017 at 14:03 UTC ( [id://1190976]=note: print w/replies, xml ) Need Help??


in reply to Re: match a word and delete last line
in thread match a word and delete last line

tybalt89, how do I modify to remove the previous line word if doesn't include (d,_,-) for example if only says Text.
sample-text file Text-1 matching the 1st line matching the last line text text_1 sample-text file text-2 matching the 1st line matching the last line text_1 text-2 text sample-text file text matching the 1st line matching the last line
I need to remove the following ( text ) too-
..................... text_1 text-2 text sample-text file text matching the 1st line matching the last line

Replies are listed 'Best First'.
Re^3: match a word and delete last line
by tybalt89 (Monsignor) on May 23, 2017 at 14:17 UTC

    Try this, but your question is a little unclear. Please give an exact input and output test case, not a partial one.

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1190966 use strict; use warnings; $_ = do { local $/; <DATA> }; s/^(\w+(?:[-_]\d+)?)\n(?=.*\1\b)//gm; print; __DATA__ Text_1 sample-text file Text_1 matching the 1st line matching the last line Text text_1 text-2 sample-text file text-2 matching the 1st line matching the last line text_1 text-2 text sample-text file text matching the 1st line matching the last line
      That works. I was missing (?: ). Thank you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found