If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Replace new line with comma

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-07, 06:51
J.Poornima J.Poornima is offline
Registered User
 
Join Date: Mar 2007
Posts: 25
Replace new line with comma

Hi Experts,

The following is my contents of the file

ABC

EFG

My output should be as follows

ABC,EFG

How can I acheive this with sed?

Thanks in advance
Regards,
Poornima
Reply With Quote
  #2 (permalink)  
Old 12-06-07, 04:51
radoulov radoulov is offline
Registered User
 
Join Date: May 2007
Location: Milano, Italy
Posts: 22
Is this the entire input file?
Reply With Quote
  #3 (permalink)  
Old 12-06-07, 05:38
J.Poornima J.Poornima is offline
Registered User
 
Join Date: Mar 2007
Posts: 25
For an example I have just given two lines. But in reality my input file consists of 100's of lines.

Is there way to acheive my need using SED or AWK?
Reply With Quote
  #4 (permalink)  
Old 12-06-07, 06:11
radoulov radoulov is offline
Registered User
 
Join Date: May 2007
Location: Milano, Italy
Posts: 22
If awk is acceptable:

Code:
awk 'NR==1{x=$0;next}NF{x=x","$0}END{print x}' filename
Use nawk or /usr/xpg4/bin/awk on Solaris.
Reply With Quote
  #5 (permalink)  
Old 12-06-07, 06:59
parangiri parangiri is offline
Registered User
 
Join Date: Feb 2007
Location: Chennai, TN
Posts: 68
if sed,
sed -e :a -e N -e 's/\n/,/' -e ta yourfile.txt >newfile.txt

reference
http://www.linuxquestions.org/questi...ng-sed-191121/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On