using sed to append text to the end of each line | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

using sed to append text to the end of each line

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-29-2005
Redg Redg is offline
Registered User
 
Join Date: Aug 2005
Last Activity: 30 August 2005, 4:44 PM EDT
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
using sed to append text to the end of each line

Anyone know how to use SED to append a comma to the end of each line

example:

field1,field2,field3,field4

If i Cat /textfile ---- How can i append the end of /textfile with a comman?
Sponsored Links
    #2  
Old 08-29-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 24 November 2014, 4:08 PM EST
Location: Foxborough, MA
Posts: 7,668
Thanks: 153
Thanked 586 Times in 551 Posts

Code:
echo 'a,b,c' | sed 's/$/,/'

Sponsored Links
    #3  
Old 08-29-2005
Redg Redg is offline
Registered User
 
Join Date: Aug 2005
Last Activity: 30 August 2005, 4:44 PM EDT
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Works Great...Thanks for your help
    #4  
Old 07-11-2006
gfhgfnhhn gfhgfnhhn is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 16 April 2007, 6:07 AM EDT
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
can u explain the syntax a little bit
about 'a,b,c' part
Sponsored Links
    #5  
Old 07-11-2006
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
Quote:
Originally Posted by gfhgfnhhn
can u explain the syntax a little bit
about 'a,b,c' part
a,b,c is just a placeholder. It can be anything; wrt the OP, it is the same as
field1,field2,field3,field4
Sponsored Links
    #6  
Old 07-11-2006
madhunk madhunk is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 22 May 2013, 5:40 PM EDT
Posts: 95
Thanks: 1
Thanked 0 Times in 0 Posts
I am not sure if I have to start another thread or request for an answer in the same thread..

Just wondering how we can append tabs at the end of each line...
Data:
field1, field2, field3, field4
1 2
3 4 5

Append tab on field3 and field4 for the first row..and
Append tab on field4 for the second row.

Please advise...
Madhu
Sponsored Links
    #7  
Old 07-25-2006
GT Premi GT Premi is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 1 October 2009, 2:11 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Not quite sure what you're saying, but assuming you have a datafile that contains:

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

and you want it formatted as you've shown, you could do:
awk '{print $1, $2"\n"$3, $4, $5"\n\n"}' <datafile>

to get:
1 2
3 4 5

1 2
3 4 5
etc.

The above could also be accomplished with "awk '{printf}'".

I can't see the usefulness of adding tabs to the end of each line unless you plan to paste a file to this one, but you can do:
sed 's/$/[press TAB button here]/' datafile > newfile
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
find a certain line and append text to the end of the line peachclift Shell Programming and Scripting 2 12-19-2011 04:10 PM
Append text to end of every line spacebase Shell Programming and Scripting 4 09-13-2011 07:45 PM
append each line with text dvah Shell Programming and Scripting 2 03-10-2011 01:40 PM
Append text to end of line on all lines giles.cardew Shell Programming and Scripting 5 11-26-2010 10:10 AM
sed - append text to every line jgrogan UNIX for Dummies Questions & Answers 3 02-01-2010 08:06 AM



All times are GMT -4. The time now is 09:37 PM.