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
$

link|improve this question

79% accept rate
feedback

2 Answers

up vote 2 down vote accepted

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.

link|improve this answer
hey, it worked!!:) no new line before the pre pastebin.com/raw.php?i=ywc16UMk THANK YOU!! god bless the open source community:) – LanceBaynes Jan 19 '11 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! – LanceBaynes Jan 19 '11 at 23:01
@user: Sorry about that, try the revised version. – Dennis Williamson Jan 20 '11 at 0:37
that worked perfectly :O long live you :) thanks:) – LanceBaynes Jan 20 '11 at 13:49
@user: If you found this answer useful, please mark it as accepted (you can also upvote it if you like). – Dennis Williamson Jan 20 '11 at 15:04
feedback

Would piping it into sed '/^$/d' do what you want ?

link|improve this answer
That would delete all empty lines which may not be desirable. – Dennis Williamson Jan 20 '11 at 0:38
The original question is so confused it is difficult to fogure out exactly what is being asked. The clarification in the comments clearly makes my answer wrong. – Iain Jan 20 '11 at 8:11
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.