Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    6

    Unanswered: 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

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    nawk -v RS='' -v OFS="," '$1=$1' file

  3. #3
    Join Date
    Jun 2004
    Posts
    6

    Thumbs up

    Cool. This works perfect.

    Thank you so much.

  4. #4
    Join Date
    Oct 2003
    Posts
    19
    Could you please explain how that "awk" statement works in this case .
    Thanks
    Saurav

  5. #5
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •