I'm trying to add a line at the beginning of a file, using
echo 'time/F:x1:x2' | cat - file.txt>newfile.txt
But this produces line breaks at each line in the new file (except for after the added 'time/F:x1:x2' line). Any ideas on how to avoid this?
Use
-n
to disable the trailing newline:There are other ways, too:
How about
or
Actually you don't even need the
echo
and pipe if you're using bash. Just use a herestring: