Hi,
I'm using the following to insert lines into file:
sed $\{rowNr\}i'\\
first row\\
second row\\
third row\\
' file.txt
How can I add tab in front of each added line? "\t" or actual TAB does not seem to work?
Thanks!
Hi,
I'm using the following to insert lines into file:
sed $\{rowNr\}i'\\
first row\\
second row\\
third row\\
' file.txt
How can I add tab in front of each added line? "\t" or actual TAB does not seem to work?
Thanks!
Hi.
Here are 3 ways of doing it with GNU sed:
#!/usr/bin/env sh
# @(#) s1 Demonstrate insert lines, TABs with sed.
set -o nounset
echo
debug=":"
debug="echo"
## Use local command version for the commands in this demonstration.
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash sed cat
echo
# Create test file.
cat >data1 <<'EOF'
alpha
beta
gamma
EOF
echo " Input file:"
cat -n data1
echo
echo " Results from sed:"
sed 2i'\
\tfirst row (used \\t)\
second row (used TAB: ^I)\
\o011third row (used \\o011, escaped octal)\
' data1 |
cat -n
exit 0
Producing:
% ./s1
(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU sed version 4.1.2
cat (coreutils) 5.2.1
Input file:
1 alpha
2 beta
3 gamma
Results from sed:
1 alpha
2 first row (used \t)
3 second row (used TAB: ^I)
4 third row (used \o011, escaped octal)
5
6 beta
7 gamma
Best wishes ... cheers, drl