Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-29-2005
Registered User
 
Join Date: Aug 2005
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
ɹoʇɐɹǝpoɯ
 
Join Date: Feb 2005
Location: Foxborough, MA
Posts: 7,384
Thanks: 112
Thanked 486 Times in 458 Posts

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

Sponsored Links
    #3  
Old 08-29-2005
Registered User
 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Works Great...Thanks for your help
    #4  
Old 07-11-2006
Registered User
 
Join Date: Mar 2006
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
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
Registered User
 
Join Date: Nov 2005
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
Registered User
 
Join Date: Jul 2006
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 03:10 PM
Append text to end of every line spacebase Shell Programming and Scripting 4 09-13-2011 06:45 PM
append each line with text dvah Shell Programming and Scripting 2 03-10-2011 12:40 PM
Append text to end of line on all lines giles.cardew Shell Programming and Scripting 5 11-26-2010 09:10 AM
sed - append text to every line jgrogan UNIX for Dummies Questions & Answers 3 02-01-2010 07:06 AM



All times are GMT -4. The time now is 04:35 AM.