1

The two "sed lines" only differ by a "\n" below..
How can i get this output [no new line before the </pre>]? [ http://pastebin.com/raw.php?i=ED34jvtF ]:
.
.
something3
</pre>
something4
.
.


$ echo -e 'something1\nsomething2\nsomething3\n\n</pre>\nsomething4\nsomething5'; echo "######################################"; echo -e 'something1\nsomething2\nsomething3\n\n</pre>\nsomething4\nsomething5' | sed -e N -e N -e "s#\n</pre>#</pre>#g" -e P -e D
something1
something2
something3

</pre>
something4
something5
######################################
something1
something2
something3</pre>
something4
something5
$
$ echo -e 'something1\nsomething2\nsomething3\n\n</pre>\nsomething4\nsomething5' | sed -e N -e N -e "s#\n</pre>#\n</pre>#g" -e P -e D
something1
something2
something3

</pre>
something4
something5
$

1 Answer 1

2

Give this a try:

sed 's|\(.\+\)\(</pre>\)$|\1\n\2|;t;N;\|\n</pre>$|s|^[[:blank:]]*\n||;P;D' inputfile

The result:

something1
something2
something3
</pre>
something4
something5
######################################
something1
something2
something3
</pre>
something4
something5

Notice that both instances of </pre> are on a line by themselves without a preceding blank line.

Edit: Fixed a problem with deleting the wrong lines.

4
  • hey, it worked!!:) no new line before the pre pastebin.com/raw.php?i=ywc16UMk THANK YOU!! god bless the open source community:) Jan 19, 2011 at 22:34
  • oops: pastebin.com/raw.php?i=0fV15Yg2 it deletes not just the empty lines before </pre> - because it deletes one line before it. i only need to delete the empty line before </pre>! but thank you! Jan 19, 2011 at 23:01
  • @user: Sorry about that, try the revised version. Jan 20, 2011 at 0:37
  • @user: If you found this answer useful, please mark it as accepted (you can also upvote it if you like). Jan 20, 2011 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .