Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

sed: how to insert tab?

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-28-2007
Juha Juha is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 18 August 2016, 3:23 AM EDT
Posts: 46
Thanks: 2
Thanked 0 Times in 0 Posts
sed: how to insert tab?

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!
Sponsored Links
    #2  
Old Unix and Linux 10-29-2007
Yogesh Sawant's Unix or Linux Image
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 5 December 2016, 11:37 AM EST
Location: Rossem, Tazenda
Posts: 1,213
Thanks: 7
Thanked 18 Times in 17 Posts
check if you can try the possibilities given by cfajohnson here
Sponsored Links
    #3  
Old Unix and Linux 10-29-2007
drl's Unix or Linux Image
drl drl is offline Forum Advisor  
Registered Voter
 
Join Date: Apr 2007
Last Activity: 5 December 2016, 4:29 PM EST
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,019
Thanks: 147
Thanked 332 Times in 292 Posts
Hi.

Here are 3 ways of doing it with GNU sed:

Code:
#!/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:

Code:
% ./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
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search and Insert parthmittal2007 Shell Programming and Scripting 6 01-31-2012 11:24 AM
insert txt in the row suryanarayana Shell Programming and Scripting 5 10-05-2009 09:38 AM
How do I insert x'0D' ? rchuttke UNIX for Dummies Questions & Answers 2 03-26-2008 01:03 PM
How to insert child job under a box job? xejatt UNIX for Dummies Questions & Answers 4 03-12-2008 05:08 PM
Cut Paste and Insert Help PradeepRed Shell Programming and Scripting 5 12-09-2005 05:49 AM



All times are GMT -4. The time now is 10:49 PM.