Results 1 to 3 of 3
Like Tree2Likes
  • 1 Post By vijay
  • 1 Post By Katie

Thread: Transpose multiple columns to rows - unix

  1. #1
    Senior Member vijay's Avatar
    Join Date
    May 2012
    Location
    Hyderabad
    Posts
    515

    Transpose multiple columns to rows - unix

    My source file contains the following data.

    Code:
    > cat filename
    10,A,B,C
    20,X,Y,Z
    Keeping the first column as it is, i want to transpose the remaining columns into multiple rows. The output should look as

    Code:
    10,A
    10,B
    10,C
    20,X
    20,Y
    20,Z
    How to do this using unix command.
    sushil010 likes this.

  2. #2
    Member
    Join Date
    Nov 2012
    Posts
    34
    An awk solution:

    Code:
    awk 'BEGIN {FS=OFS=","} { for (field = 2; field <= NF; field++ ) print $1, $field }' filename
    sushil010 likes this.

Similar Threads

  1. Replies: 2
    Last Post: 06-05-2012, 05:52 AM
  2. Replies: 1
    Last Post: 06-03-2012, 07:15 PM

Bookmarks

Posting Permissions

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