Reputation: 71
There is the following which will truncate a file to take the first line and overwrite it, I wonder if there is a cleaner way then to do this:
touch temp.txt; cat versions.txt | head -1 > temp.txt; mv temp.txt versions.txt
Note that this does not work:
cat versions.txt | head -1 > versions.txt
and the touch
is not necessary on most systems
Upvotes: 2
Views: 349
Reputation: 23374
Here's one way of doing it in-place
ex -c ':2,$d' -c ':wq' versions.txt
Upvotes: 4
Reputation: 593
Ho about this
ONE=`awk 'NR==1 {print;exit}' versions.txt`&& echo $ONE>versions.txt
Upvotes: 3
Reputation: 33307
You could do it with sed in one command:
sed -i -n 1p versions.txt
Upvotes: 3