Deletion of last Empty paragraph

Hello,

I hava a file resulting from a script which ends as follows:

 
172|18|FOOTER|DISCLOSURE||16�
173|0|FOOTER|FILE||18�

note the paragraph signs are only placed to demonstrate the problem

I want it to return the same last lines but without the last empty paragraph i.e:

 
172|18|FOOTER|DISCLOSURE||16�
173|0|FOOTER|FILE||18

What i need is no empty line at the end of the file

I tried all the following but they either did nothing or deleted the last line instead of the last empty line.

 
sed '/^$/N;/\n$/D'
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
sed '$d'
sed '/^$/d' 
sed '/./!d'

any help would be much appreciated

AFAIK, according POSIX standard this is not a text file. You can get some problems working with it (for example "cat THISFILE | while read line; do echo $line; done" wouldn't emit the last line).

172|18|FOOTER|DISCLOSURE||16�
173|0|FOOTER|FILE||18

This one is:

172|18|FOOTER|DISCLOSURE||16�
173|0|FOOTER|FILE||18�

And only this has the empty last line:

172|18|FOOTER|DISCLOSURE||16�
173|0|FOOTER|FILE||18�
�
1 Like

Hi,

Try next command:

$ perl -pe 'chomp if eof' infile

Regards,
Birei

1 Like

Thank you for your replies. The perl script worked like a charm. Thank you very much