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 > Need assistance - converting rows to columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-12-08, 10:17
jamesadennis jamesadennis is offline
Registered User
 
Join Date: Sep 2008
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 09-12-08, 15:04
Bob4480 Bob4480 is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 09-13-08, 16:31
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,612
This isn't pretty AWK, but:
Code:
	{if (1 == NR % 7) { print buf; buf = $0 } else { buf = buf "," $0 }}
END	{ print buf }
-PatP
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