Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why sed removes last line?

Tags:

unix

sed

$ cat file.txt
one
two
three
$ cat file.txt | sed "s/one/1/"
1
two

Where is the word "three"?

UPDATED: There is no line after the word "three".

like image 475
Volodymyr Bezuglyy Avatar asked Mar 03 '10 16:03

Volodymyr Bezuglyy


1 Answers

As Ivan suggested, your text file is missing the end of line (EOL) marker on the final line. Since that's not present, three is printed out by sed but then immediately over-written by your prompt. You can see it if you force an extra line to be printed.

sed 's/one/1/' file.txt && echo

This is a common problem since people incorrectly think of the EOL as an indication that there's a following line (which is why it's commonly called a "newline") and not as an indication that the current line has ended.

like image 122
jamessan Avatar answered Sep 22 '22 14:09

jamessan