Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

sed: how to insert tab?

Shell Programming and Scripting


Closed Linux or Unix Question    
 
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: 7 March 2013, 1:15 AM EST
Posts: 41
Thanks: 0
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: 22 April 2015, 4:51 AM EDT
Location: Rossem, Tazenda
Posts: 1,211
Thanks: 6
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 online now Forum Advisor  
Registered Voter
 
Join Date: Apr 2007
Last Activity: 26 April 2015, 1:12 PM EDT
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 1,764
Thanks: 57
Thanked 232 Times in 208 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 10:24 AM
insert txt in the row suryanarayana Shell Programming and Scripting 5 10-05-2009 08:38 AM
How do I insert x'0D' ? rchuttke UNIX for Dummies Questions & Answers 2 03-26-2008 12:03 PM
How to insert child job under a box job? xejatt UNIX for Dummies Questions & Answers 4 03-12-2008 04:08 PM
Cut Paste and Insert Help PradeepRed Shell Programming and Scripting 5 12-09-2005 04:49 AM



All times are GMT -4. The time now is 01:12 PM.