Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 07: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, 05: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, 06: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, 07: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, 07:59
parangiri parangiri is offline
Registered User
 
Join Date: Feb 2007
Location: Chennai, TN
Posts: 59
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

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