Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2008
    Posts
    2

    Unanswered: Need assistance - converting rows to columns

    Hello,

    I have a fairly simple file which will consist of data from about 3000 servers. The file looks like this:

    SERVERNAME
    PASS
    FAIL
    PASS
    PASS
    PASS
    ...
    SERVERNAME
    FAIL
    PASS
    NG
    PASS
    FAIL


    What I need to do is create rows for each server name with all their pass/fails. I want the data comma delimited, as this will be imported into a database.
    SERVERNAME,PASS,FAIL,PASS,PASS,PASS
    SERVERNAME,FAIL,PASS,NG,PASS,FAIL

    I've tried using nawk and awk to do this based on examples I've seen online, but so far no luck.

    This is on AIX 5.3 Tech Level 8 by the way, using standard AIX awk/nawk.

    Thanks in advance for your assistance.

    Best regards,


    Jamie

  2. #2
    Join Date
    Feb 2004
    Location
    Los Angeles, CA
    Posts
    28
    Try this;

    Code:
    COL_NUM=0
    while read INPUT
    do
    (( COL_NUM = COL_NUM + 1))
       case ${COL_NUM} in
          1) COL1=${INPUT};;
          2) COL2=${INPUT};;
          3) COL3=${INPUT};;
          4) COL4=${INPUT};;
          5) COL5=${INPUT};;
          6) COL6=${INPUT};;
       esac
       if [ ${COL_NUM} -eq 6 ]
       then
          echo "${COL1},${COL2},${COL3},${COL4},${COL5},${COL6}"
          COL_NUM=0
       fi
    done < server.output
    This is assuming you have 6 columns and each server will give you 6 statuses.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    This isn't pretty AWK, but:
    Code:
    	{if (1 == NR % 7) { print buf; buf = $0 } else { buf = buf "," $0 }}
    END	{ print buf }
    -PatP

Posting Permissions

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