This question already has an answer here:
- Unwanted line break using echo and cat 3 answers
- How to insert a text at the beginning of a file? 14 answers
I want to add a line to the beginning of a text file. I have input.txt:
line1
line2
line3
and want to add the line 'time/F:x1:x2' to end up with
time/F:x1:x2
line1
line2
line3
I'm trying to do this with
echo 'time/F:x1:x2' | cat - input.txt>output.txt
but what I get is
time/F:x1:x2
line1
line2
line3
that is, I get empty lines I don't want. How can I avoid this? [edit: This is not a duplicate of Unwanted line break using echo and cat since I wrongly asked about line breaks there - what I really want to avoid is empty lines.]