Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: how to remove block of data from file based on string

by Xiong (Hermit)
on Mar 14, 2012 at 23:22 UTC ( [id://959689]=note: print w/replies, xml ) Need Help??


in reply to how to remove block of data from file based on string

Sorry; I can't answer your question because I can't understand it. Let me try to show you how I think you might ask.


I have the following input data:

Input:
block1 start hehu7 gjwsdh hsjdhj remove hjhsj jdkwj hwjdhjwh end block2 start crgr hjdhwjd wjdkwj wkjw g hjhd end

I want to remove the string that starts with 'start', includes 'remove', and ends with 'end':

Output:
block1 block2 start crgr hjdhwjd wjdkwj wkjw g hjhd end

Of course this may not be what you want at all. Why not try to be a bit more explicit and we'll see what we can do to help?

Death only closes a Man's Reputation, and determines it as good or bad. —Joseph Addison

Replies are listed 'Best First'.
Re^2: how to remove block of data from file based on string
by royalreddy (Initiate) on Mar 14, 2012 at 23:24 UTC
    ya, this is what I want.......
      Here is your solution:
      my $str = <<'EOB'; start hehu7 gjwsdh hsjdhj remove hjhsj jdkwj hwjdhjwh end start crgr hjdhwjd wjdkwj wkjw g hjhd end EOB while ($str =~ /(\bstart\b.*?\bend\b\s*)/gs) { my $block = $1; if ($block =~ /\bremove\b/) { $str =~ s/\Q$block\E//; } } print $str; __END__ start crgr hjdhwjd wjdkwj wkjw g hjhd end
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found