A test
T 1999 Some text spaces and numbers
D 01012002
#
Here's what I have tried:
s/A\s+test\nT\s+(.*)\nD\s+01012002\n#\n//g;
s/A\s+test\nT\s+(.*)\nD\s+01012002\n#\n//g;
s/(A\s+test\nT\s+.*\nD\s+01012002\n#\n)//g;
s/A\A test\nT (.*)\nD 01012002\n#\n//g;
Thank you VERY much :D
Sincerely,
Joe Belmaati
Copenhagen Denmark
You can get it to do what you want by adding the "s" option along with your "g" option. The "s" option causes Perl to consider the text as one big string, regardless of newlines.
Look under "s/PATTERN/REPLACEMENT/egimosx" in perlop for details.
Your first attempt plus the "s" should work, although you might want to check for beginning of line, if appropriate:
s/^A\s+test\nT\s+(.*)\nD\s+01012002\n#\n//gs;
Begins with an A, multiple lines, ends with a #. It makes a difference whether you're going through a chunk in a scalar or line by line through a file. I picked line-by-line because sometimes I don't know the right thing to tell the m modifier. :-) First I came up with this quickie.
$content =~ s/[ATD#].*//g;
Works to strip those lines, but will also kill anything else that begins with an A, T, D, or #. If you have a specific pattern, you could substitute the .* with patterns. I got this to work doing a line by line read:
$content =~ s/^[ATD#](\s*\w{4}¦\s*\d+.*)*\s*$//g;
^ beginning of line
[ATD#] followed by any of these
\s*\w{4} maybe followed by a space, then 4 word chars
¦ OR
\s*\d+.* maybe a whitespace, followed by any number of digits, followed by anything
* either of these may or may not exist (this gets the # only)
*\s$ Followed by a whitespace (includes newlines) at the end of the line. $
Anxious also to see a better solution, because I know this one's probably all wrong!
rocknbil, your version worked, but it is too greedy in that I have some other sequences that should remain, and they contain similar patterns example
A test
T 1999 Text 5747 spaces numbers
M blah blah more text special character ´´#"" and numbers
D 01012002
#
The above mentioned sequence should remain. That's why I can't really do it line by line...