-1

This question is an exact duplicate of:

I've a .txt file from which I'd like to delete the last, empty line. I've tried a ridiculous number of sed, perl and awk commands found on the internet, but none of them has worked.

I don't know what does it mean, but I leave you the output of od -c myfile.txt

od -c myfile.txt
0000000   2   1   7   .   2   9   .   2   3   0   .   0   /   2   4  \n
0000020   1   9   4   .   1   9   7   .   1   5   1   .   1   6   0   /
0000040   2   7  \n   1   9   4   .   1   8   8   .   6   6   .   0   /
0000060   2   3  \n   1   9   4   .   1   8   8   .   6   5   .   0   /
0000100   2   4  \n   1   9   4   .   1   4   2   .   1   6   8   .   2
0000120   4   8   /   2   9  \n   1   9   4   .   1   4   2   .   2   4
0000140   .   1   2   8   /   2   9  \n   1   9   4   .   1   3   7   .
0000160   1   3   3   .   0   /   2   4  \n   1   9   4   .   1   1   2
0000200   .   1   4   .   0   /   2   3  \n   1   9   4   .   1   1   2
0000220   .   1   3   .   1   2   8   /   2   5  \n   1   9   4   .   1
0000240   1   2   .   1   3   .   6   4   /   2   6  \n   1   9   4   .
0000260   1   1   2   .   1   3   .   3   2   /   2   7  \n   1   9   4
0000300   .   1   1   2   .   1   3   .   1   6   /   2   8  \n   1   9
0000320   4   .   1   1   2   .   1   2   .   0   /   2   4  \n   1   9
0000340   4   .   1   1   2   .   1   0   .   0   /   2   3  \n   1   9
0000360   4   .   1   1   2   .   9   .   0   /   2   4  \n   1   9   4
0000400   .   1   1   2   .   8   .   2   2   4   /   2   7  \n   1   9
0000420   4   .   1   1   2   .   8   .   2   0   8   /   2   8  \n   1
0000440   9   4   .   1   9   7   .   2   0   8   .   0   /   2   4  \n
0000460   1   9   4   .   2   4   0   .   5   4   .   0   /   2   4  \n
0000500   2   1   3   .   2   0   4   .   6   2   .   0   /   2   3  \n
0000520   2   1   3   .   2   0   4   .   6   0   .   0   /   2   4  \n
0000540   2   1   3   .   2   0   4   .   5   6   .   0   /   2   2  \n
0000560   2   1   3   .   2   0   4   .   5   2   .   0   /   2   2  \n
0000600   2   1   3   .   2   0   4   .   5   0   .   0   /   2   4  \n
0000620   2   1   3   .   2   0   4   .   4   8   .   0   /   2   3  \n
0000640   2   1   3   .   2   0   4   .   3   2   .   0   /   2   0  \n
0000660   2   1   3   .   2   8   .   1   4   8   .   0   /   2   8  \n
0000700   2   1   2   .   2   1   3   .   2   1   1   .   3   2   /   2
0000720   8  \n   2   1   2   .   2   1   3   .   9   5   .   3   2   /
0000740   2   8  \n   2   1   2   .   1   7   .   1   7   6   .   0   /
0000760   2   2  \n   2   1   2   .   1   7   .   1   6   8   .   0   /
0001000   2   1  \n   1   9   5   .   2   3   7   .   3   2   .   0   /
0001020   2   4  \n   1   9   5   .   1   6   5   .   6   8   .   1   2
0001040   8   /   2   6  \n   1   9   4   .   2   5   2   .   6   1   .
0001060   1   3   2   /   3   0  \n   1   9   4   .   2   5   1   .   2
0001100   0   8   .   0   /   2   1  \n   1   9   4   .   1   1   2   .
0001120   8   .   2   0   0   /   2   9  \n   1   9   4   .   1   1   2
0001140   .   8   .   1   2   8   /   2   6  \n   1   9   4   .   1   1
0001160   2   .   8   .   0   /   2   5  \n   8   2   .   1   9   9   .
0001200   1   8   5   .   0   /   2   4  \n   8   2   .   1   9   9   .
0001220   1   8   4   .   2   4   8   /   3   0  \n   8   2   .   1   9
0001240   9   .   1   8   4   .   2   4   0   /   2   9  \n   8   2   .
0001260   1   9   9   .   1   8   4   .   2   2   4   /   2   8  \n   8
0001300   2   .   1   9   9   .   1   8   4   .   1   9   2   /   2   7
0001320  \n   8   2   .   1   9   9   .   1   8   4   .   1   2   8   /
0001340   2   6  \n   8   2   .   1   9   9   .   1   8   4   .   0   /
0001360   2   5  \n   8   2   .   1   9   9   .   1   8   2   .   0   /
0001400   2   3  \n   8   2   .   1   9   9   .   1   7   8   .   0   /
0001420   2   3  \n   8   2   .   1   9   9   .   1   7   7   .   0   /
0001440   2   4  \n   8   2   .   1   9   9   .   1   7   4   .   0   /
0001460   2   3  \n   8   2   .   1   9   9   .   1   7   1   .   0   /
0001500   2   4  \n   8   2   .   1   9   9   .   1   6   9   .   0   /
0001520   2   4  \n   8   2   .   1   9   9   .   1   6   0   .   0   /
0001540   2   1  \n   7   9   .   1   3   3   .   0   .   0   /   1   9
0001560  \n   6   2   .   1   4   2   .   7   2   .   1   1   2   /   2
0001600   9  \n   8   2   .   1   9   9   .   1   8   6   .   6   4   /
0001620   2   6  \n   8   2   .   1   9   9   .   1   8   7   .   1   2
0001640   8   /   2   5  \n   1   9   4   .   1   1   2   .   0   .   0
0001660   /   2   1  \n   1   9   4   .   1   1   1   .   2   0   2   .
0001700   0   /   2   3  \n   1   9   4   .   1   1   1   .   1   6   3
0001720   .   0   /   2   4  \n   1   9   4   .   1   1   0   .   1   7
0001740   6   .   0   /   2   0  \n   1   9   4   .   1   0   0   .   4
0001760   9   .   0   /   2   5  \n   1   9   3   .   2   1   0   .   5
0002000   .   1   3   6   /   2   9  \n   1   9   2   .   1   9   4   .
0002020   2   5   0   .   9   6   /   2   7  \n   1   9   2   .   1   9
0002040   4   .   2   4   3   .   7   6   /   3   0  \n   1   9   2   .
0002060   1   9   4   .   2   1   4   .   1   1   2   /   2   8  \n   1
0002100   9   2   .   1   3   0   .   2   4   3   .   0   /   2   8  \n
0002120   1   9   2   .   1   3   0   .   1   9   6   .   1   2   8   /
0002140   2   7  \n   1   9   2   .   8   9   .   2   5   4   .   0   /
0002160   2   4  \n   1   9   2   .   8   9   .   2   4   0   .   6   4
0002200   /   2   7  \n   1   9   2   .   8   9   .   5   4   .   0   /
0002220   2   5  \n   1   9   2   .   8   9   .   3   .   8   /   3   0
0002240  \n
0002241

How the hell can I delete that last, empty line?

marked as duplicate by Ward, Sven Mar 27 '16 at 12:21

This question was marked as an exact duplicate of an existing question.

  • Instead of od -c myfile.txt post the output of cat myfile.txt | base64 – kbtzr Mar 26 '16 at 22:56
  • Use the edit function for this, not the answer field. – Sven Mar 26 '16 at 23:04
  • If perl is avaiable in the system use perl -i -pe "chomp if eof" myfile.txt source If its not, we can make that damn sed to work... – kbtzr Mar 26 '16 at 23:19
  • Where do you see a 'last, empty line'? You have text 192.89.3.8/30 then a newline (which together make up a nonempty last line) then end-of-file. – dave_thompson_085 Mar 27 '16 at 6:28
  • I moved this question here: serverfault.com/questions/766334/… – BillBallz Mar 27 '16 at 11:41
0

You can save the all content witot the last line in a new file:

sed '$d' myfile.txt >> myfile2.txt
  • 1
    or add -i to modify the file in place – kbtzr Mar 26 '16 at 23:26

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