Reputation: 97
I am trying to add a line of text to the top of a text file with tab delimiters.
sed -i '1s/^/x,y,z\n/' INPUTFILE.txt
^^This of course yields "x,y,z" in the top row of the input file.
sed -i '1s/^/x'\t'y'\t'z\n/' INPUTFILE.txt
^^This yields "xtytz" in the top row of the input file.
What is the correct syntax to add a tab between the entries x,y, and z?
Thanks!
Update:
Two suggestions ended up working here:
using an actual tab as a "character" between x,y,and z
sed -i '1s/^/x y z\n/' INPUTFILE.txt
Using \t, but without the '
surrounding it... Just drop it in!
sed -i '1s/^/x\ty\tz\n/' INPUTFILE.txt
Big thanks to all for input.
Upvotes: 2
Views: 5124
Reputation: 1446
Your second try is almost correct. Just delete '
separating \t
(GNU sed 4.2.1)
sed -i '1s/^/x\ty\tz\n/' INPUTFILE.txt
However, answer suggested by glenn jackman seems to be more elegant.
Upvotes: 2
Reputation: 246867
This works with my sed (GNU sed 4.2.1): there's a newline immediately after the backslash
seq 5 | sed '1i\
a\tb\tc'
a b c
1
2
3
4
5
Upvotes: 2