need to insert two columns (or two feilds) at the begining of the table

Hey guys/gals,

So here is what i'm starting with...its a Solaris patch diag output.
bash-3.0# pca -l
Using /var/tmp/patchdiag.xref from Oct/20/08
Host: seiftsx4140 (SunOS 5.10/Generic_127128-11/i386/i86pc)
List: missing

Patch IR CR RSB Age Synopsis
------ -- - -- --- --- -------------------------------------------------------
119255 53 < 59 RS- 21 SunOS 5.10_x86: Install and Patch Utilities Patch
118668 15 < 17 -S- 106 JavaSE 5.0_x86: update 16 patch (equivalent to JDK 5.0u16)
118736 01 < 02 --- 153 SunOS 5.10_x86: usr/sbin/rpc.nisd_resolv Patch
118825 01 < 02 --- 152 SunOS 5.10_x86: sort patch
119043 10 < 11 R-- 140 SunOS 5.10_x86: svccfg & svcprop patch
119060 39 < 44 RS- 82 X11 6.6.2_x86: Xsun patch
119091 26 < 32 R-- 42 SunOS 5.10_x86: Sun iSCSI Device Driver and Utilities
119214 16 < 17 -S- 231 NSS_NSPR_JSS 3.11.9_x86: NSPR 4.7 / NSS 3.11.9 / JSS 4.2.6
119247 32 < 34 R-- 61 SunOS 5.10_x86: Manual Page updates for Solaris 10
119253 25 < 29 R-- 22 SunOS 5.10_x86: System Administration Applications Patch
119281 17 < 18 --- 141 CDE 1.6_x86: Runtime library patch for Solaris 10
119398 06 < 07 --- 107 SunOS 10_x86: Patch for North America Region locale issues
--------------------------------------
I then run this...

pca -l | awk '{print $1";"$2";"$4";"$5";"$6";"$7,$8,$9,$10,$12,$15,$16,$18,$19,$20,$21,$22}' |sed -e '1,6 d'

--------------------------------------
and I get this in return....

119255;53;59;RS-;21;SunOS 5.10_x86: Install and Utilities
118668;15;17;-S-;106;JavaSE 5.0_x86: update 16 (equivalent 5.0u16)
118736;01;02;---;153;SunOS 5.10_x86: usr/sbin/rpc.nisd_resolv Patch
118825;01;02;---;152;SunOS 5.10_x86: sort patch
119043;10;11;R--;140;SunOS 5.10_x86: svccfg & patch
119060;39;44;RS-;82;X11 6.6.2_x86: Xsun patch
119091;26;32;R--;42;SunOS 5.10_x86: Sun iSCSI Driver
119214;16;17;-S-;231;NSS_NSPR_JSS 3.11.9_x86: NSPR 4.7 NSS JSS 4.2.6
119247;32;34;R--;61;SunOS 5.10_x86: Manual Page for
119253;25;29;R--;22;SunOS 5.10_x86: System Administration Patch
119281;17;18;---;141;CDE 1.6_x86: Runtime library for
119398;06;07;---;107;SunOS 10_x86: Patch for America issues
-----------------------------------------
what I'm doing is dumping this into a mysqlDB, however I think i need to add date and hostname fields to link table in my php frontend. So, Is there a way to make the output look like this...

$hostname;$date;119255;53;59;RS-;21;SunOS 5.10_x86: Install and Utilities
$hostname;$date;118668;15;17;-S-;106;JavaSE 5.0_x86: update 16 (equivalent 5.0u16)
$hostname;$date;118736;01;02;---;153;SunOS 5.10_x86: usr/sbin/rpc.nisd_resolv Patch

Depending on the seperation character (we can't see it here unless you use [ C O D E ] tags) you might be able to use cut or sed here, but I'm assuming it's some variable length whitespace or a tab char, so:

pca -l | tail +7 | while read line
do
  echo $hostname `date` `echo $line | awk '{print $1";"$2";"$4";"$5";"$6";"$7,$8,$9,$10,$12,$15,$16,$18,$19,$20,$21,$22}'`
done

There's far nicer ways to print out fields 1,2,4,5,6 and 7 with ; seperators followed by all remaining fields.
There's also ways to get awk to display the date and hostname.
But this should do the job (not that I tested it though, so be a tad careful :slight_smile: )

Hi Dragon,

my seperator is ';' (semi-colon)

Also, is there a better way to tell AWK to print all columns except column $3 ?

Thanks so much for you help!...i'll try this out

Thanks Dragon,

my seperator is ";" (semi-colon)

I'll give this syntax a try...

Also, would you know how to tell AWK to print every column EXCEPT column $3 ?

I could not figure that out...so that is why I defined so many print arguments in the statement...

Thanks again for all your help!!