I was recently looking for a way to remove the last line of a file foo.txt
and came across the following solution
head -n -1 foo.txt temp.txt; mv temp.txt foo.txt
which works fine. However, I also tried simply
head -n -1 foo.txt > foo.txt
which to my surprise left foo.txt
an empty text file, and I would like to know why.
I'm just getting started with unix, so it's possible my question is rather silly.
cat lol.txt | head -n-1 > lol.txt
cat lol.txt 1 2 3 4 5 6 7
– Piyush Jain Apr 11 '16 at 11:29