Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 ( #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.

  • Comment on Re: Keeping the first occurence of a pattern, and removing the other occurences
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2019-06-26 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (111 votes). Check out past polls.

    Notices?