sed: how to insert tab? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    

Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

sed: how to insert tab?

Shell Programming and Scripting

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 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?


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?

Sponsored Links
Old 10-29-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
Join Date: Sep 2006
Last Activity: 30 December 2014, 12:28 PM EST
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
Old 10-29-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered Voter
Join Date: Apr 2007
Last Activity: 24 January 2015, 1:09 PM EST
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 1,720
Thanks: 49
Thanked 209 Times in 190 Posts

Here are 3 ways of doing it with GNU sed:

#!/usr/bin/env sh

# @(#) s1       Demonstrate insert lines, TABs with sed.

set -o nounset


## 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


# Create test file.
cat >data1 <<'EOF'

echo " Input file:"
cat -n data1

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


% ./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)
     6  beta
     7  gamma

Best wishes ... cheers, drl
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:23 AM.