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 > Transform rows into comma seperated columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-04, 05:03
yahoo yahoo is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
Transform rows into comma seperated columns

I need to transform rows into columns as below:

a
b
c
d
e
f
g


to

a,b,c,d,e,f,g

Any help greatly appreciated?

Thanks
Hemant
Reply With Quote
  #2 (permalink)  
Old 06-09-04, 07:58
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
nawk -v RS='' -v OFS="," '$1=$1' file
Reply With Quote
  #3 (permalink)  
Old 06-09-04, 08:36
yahoo yahoo is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
Thumbs up

Cool. This works perfect.

Thank you so much.
Reply With Quote
  #4 (permalink)  
Old 06-17-04, 16:55
saurav101 saurav101 is offline
Registered User
 
Join Date: Oct 2003
Posts: 19
Could you please explain how that "awk" statement works in this case .
Thanks
Saurav
Reply With Quote
  #5 (permalink)  
Old 06-17-04, 17:59
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Quote:
RS The first character of the string value of RS is
the input record separator; a newline character by
default. If RS contains more than one character,
the results are unspecified. If RS is null, then
records are separated by sequences of one or more
blank lines
.

OFS The print statement output field separator; a
space character by default.
'$1=$1' - re-evaluates the records AND prints it.

Having set the RS='' makes all your records/lines appear as fields.

Specifying OFS=',' makes ',' a new field separator.
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