converting vertically grouped data to horzontal form in a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nischalinn
    New Member
    • Mar 2014
    • 16

    converting vertically grouped data to horzontal form in a file

    I've a set of data which is grouped vertically and I want that data set in horizontal form. The data is in a file. I think I've to use shell script to do the task.
    But I do not have clear idea how to do this task.
    ###### DATA IN FILE ######
    Name: client1
    Id: client101
    Address: addrs1
    Shopping Category: regular
    Items in Cart: 2

    ###### REQUIRED RESULT FORMAT ######
    Name Id Address Shopping Category Items in Cart
    client1 client101 addrs1 regular 2

    How can I do this?
    Note: the gap between the characters is 1 tab.
    Please also suggest if there is any other way to do this rather than using shell script.

    Thank You!!!
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    If the order of the columns is not important, and your inputfile is named 'vertical.txt':
    Code:
    awk -F ": " '{ h[i]=$1; a[i]=$2; i++ }END{ for (i in h) { printf("%s\t", h[i]); } print; for (i in a) { printf("%s\t", a[i]);}print; }' vertical.txt
    another way might be Excel or Calc,
    - read the file
    - select the cells
    - paste-special, and use 'transpose'

    Comment

    • nischalinn
      New Member
      • Mar 2014
      • 16

      #3
      Thanks Luuk for the reply.

      I'll try this and if there will be any confusion I'll knock again.

      Thank You!!!

      Comment

      Working...