sed with several lines, how?

Christopher Chan christopher.chan at bradbury.edu.hk
Sat Nov 27 12:36:45 UTC 2010


On Saturday, November 27, 2010 07:39 PM, Arthur Bela wrote:
> hyphen's [ - ] are just for marking the start/end of a pattern, but
> there are _not in_ the pattern!
> "OUTPUT" is what i want after "seding" the PATTERN#X's
>
>
> so i for e.g.: need the first, and second "magic"
> sed "FIRSTMAGIC" PATTERN#1
> sed "SECONDMAGIC" PATTERN#2
>
>
>
>
> PATTERN#1:
>
> -----------------------------------
> SOMETEXT#1
> <br><font size=3>SOMETEXT#2</font><br>
> <br><font size=3>SOMETEXT#3</font><br>
> SOMETEXT#4
> -----------------------------------
>
> "exact pattern", what is unique from the pattern:
> -----------------------------------
> </font><br>\n<br><font size=3>
> -----------------------------------
>
> OUTPUT:
> -----------------------------------
> SOMETEXT#1
> <br><font size=3>SOMETEXT#3</font><br>
> SOMETEXT#4
> -----------------------------------
>
>
>
>
>
> and:
>
> PATTERN#2:
>
> -----------------------------------
> SOMETEXT#1
> <br><font size=3>SOMETEXT#2</font><br>
> </font></div></body></html>
> SOMETEXT#3
> -----------------------------------
>
> "exact pattern", what is unique from the pattern:
> -----------------------------------
> </font><br>\n</font></div></body></html>
> -----------------------------------
>
> OUTPUT:
> -----------------------------------
> SOMETEXT#1
> </font></div></body></html>
> SOMETEXT#3
> -----------------------------------
>
>
> i just can't figure it out, how to "sed" when having several lines
> [nor in awk, perl..]
>

Impossible with sed. You can use awk.

Output of: 'cat testpart'

SOMETEXT#1
<br><font size=3>SOMETEXT#2</font><br>
<br><font size=3>SOMETEXT#3</font><br>
SOMETEXT#4

SOMETEXT#1
<br><font size=3>SOMETEXT#2</font><br>
</font></div></body></html>
SOMETEXT#3

Output of: awk 'BEGIN {sawpattern=0} "^SOMETEXT, ^SOMETEXT" {if (($0 ~ 
/<br><font size=3>SOMETEXT/ ) && (sawpattern == 0)) {sawpattern=1} else 
{sawpattern=0;print $0}}' testpart

SOMETEXT#1
<br><font size=3>SOMETEXT#3</font><br>
SOMETEXT#4

SOMETEXT#1
</font></div></body></html>
SOMETEXT#3

That seems to be what you are looking for.




More information about the ubuntu-users mailing list