Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Keeping the first occurence of a pattern, and removing the other occurences

by thenaz (Beadle)
on Aug 04, 2011 at 16:09 UTC ( [id://918581]=note: print w/replies, xml ) Need Help??


in reply to Keeping the first occurence of a pattern, and removing the other occurences

Use a look-behind assertion to delete all occurrences that don't follow a store name heading.

s/(?<!===\n)DEPT:\s+PRODUCE\n+/\n/g;

Of course, I am assuming the input has UNIX-style line endings (newline character only). If not, you may need to replace "\n" with "\r\n" where appropriate.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-28 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found