Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using AWK on with POSIX. 1

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
Hello all,

I am using an HP3000/MPE system, I am using the Unix sub system under this operating system. This Unix sub-system (POSIX) does have AWK and I am trying to do the following:

I have a large file that has three reports in one.

Instead of using a database, I would like to pars this file and output it to a file that I can create and has columns in it.

for example:

The three in one file has info that looks like this:
----------first file in this appended report file------
MachineName
#Incoming queue definitions
#L028B:lp=L028:sd=LPD3K.SYS:qt=raw:
#L028A:lp=L028:sd=LPD3K.SYS:qt=text:
#L031B:lp=L031:sd=LPD3K.SYS:qt=raw:
#L031A:lp=L031:sd=LPD3K.SYS:qt=text:
#L036B:lp=L036:sd=LPD3K.SYS:qt=raw:
#L036A:lp=L036:sd=LPD3K.SYS:qt=text:
#L039B:lp=L039:sd=LPD3K.SYS:qt=raw:
#L039A:lp=L039:sd=LPD3K.SYS:qt=text:

#Outgoing queue definitions
#TRMS:rm=DEV:rp=TRMS:
#L515:rm=HP00:rp=P001B:
#L515:rm=WVSCHNDM:rp=PCL28:
#L515:rm=NVBS3J2:rp=L711:
#L515:rm=NVBS3J2:rp=P99PLD00L711$:qt=auto:
#LPD010:rm=100.1.11.10:rp=Q-LPD010:
#TRMS:rm=DEV2:rp=TRMS:cl=|writer=%f|jobn=%j:qt=cctl:
#L513:rm=WVSCHNDM:rp=PCL1680:qt=auto:
hp14
-----------End of First File in this Appended report file--

-------------Start Of Second Appended File-------------

* Miscellaneous configuration items for [hp14]



H hp14 ;MPE

M HP14 ;5 ;1/C ;1;DD/MM/YY;0:00 ;0 ;0 ;LP

L



* Remote system configuration for [hp14]



S 1 ;HP00 ;8; ; ; ; ; ; ;0 ; I ;CS

N 1 ;HP00 ;MPE ;4096;180

S 8 ;HP08 ;8; ; ; ; ; ; ;0 ; I ;CS

N 8 ;HP08 ;MPE ;4096;180

S 9 ;HP09 ;8; ; ; ; ; ; ;0 ; I ;CS

N 9 ;HP09 ;MPE ;4096;180



* Device configuration for [hp14]



D 2 ;TRMS ;5 ; ; ; ; ; ;HP00 ;TRMS

X 2 ; ; ; ;cexpand

D 3 ;LP ;5 ; ; ; ; ; ;HP00 ;SYSIP

X 3 ; ;SUPPHDR1 ;TRAILR01 ;Default

D 4 ;PP ;5 ; ; ; ; ; ;HP00 ;SYSLP

X 4 ; ;HEADER01 ;TRAILR01 ;Default

D 5 ;PP80 ;5 ; ; ; ; ; ;HP00 ;SYSLP

X 5 ; ;HEADER01 ;TRAILR01 ;Default

D 6 ;LASER80 ;5 ; ; ; ; ; ;HP00 ;SYSLP

X 6 ; ;HEADER01 ;TRAILR01 ;Default

D 7 ;L257 ;5 ; ; ; ; ; ;HP00 ;L257

X 7 ; ; ; ;Default

D 8 ;REMOTE1 ;5 ; ; ; ; ; ;HP00 ;SYSLP

X 8 ; ; ; ;Default

D 9 ;REMOTE2 ;5 ; ; ; ; ; ;HP00 ;SYSIP

X 9 ; ; ; ;Default

D 13 ;P026 ;5 ; ; ; ; ; ;HP09 ;P026

X 13 ; ; ; ;Default

D 15 ;L165 ;5 ; ; ; ; ; ;HP00 ;L165

X 15 ; ; ; ;Default

D 18 ;PRT2 ;5 ; ; ; ; ; ;HP00 ;PRT2

X 18 ; ; ; ;Default

D 26 ;L024 ;5 ; ; ; ; ; ;HP00 ;L024

X 26 ; ; ; ;Default

D 32 ;PRT90 ;5 ; ; ; ; ; ;HP00 ;PRT90

X 32 ; ; ; ;Default

D 34 ;REMOTE3 ;5 ; ; ; ; ; ;HP00 ;REMOTE3

X 34 ; ; ; ;Default

D 35 ;ALTLP ;5 ; ; ; ; ; ;HP00 ;REMOTE3

X 35 ; ;HEADER01 ;TRAILR01 ;Default

D 42 ;DESKJET ;5 ; ; ; ; ; ;HP00 ;DESKJET

X 42 ; ; ; ;Default

D 47 ;RMT22 ;5 ; ; ; ; ; ;HP00 ;RMT22

X 47 ; ; ; ;Default

D 48 ;PRT22 ;5 ; ; ; ; ; ;HP00 ;PRT22

X 48 ; ;HEADER03 ; ;cexpand

D 49 ;PRT23 ;5 ; ; ; ; ; ;HP00 ;RMT23

X 49 ; ;HEADER03 ; ;Default

D 52 ;L049 ;5 ; ; ; ; ; ;HP00 ;L049

X 52 ; ; ; ;Default

D 56 ;P001 ;5 ; ; ; ; ; ;HP00 ;P001

X 56 ; ; ; ;Default

D 58 ;PRT11 ;5 ; ; ; ; ; ;HP00 ;RMT11

X 58 ; ;HEADER03 ; ;Default

D 59 ;TRMSPROD ;5 ; ; ; ; ; ;HP00 ;TRMSPROD

X 59 ; ; ; ;Default

D 88 ;FORMFICH ;5 ; ; ; ; ; ;HP00 ;FORMFICH

X 88 ; ; ; ;Default

D 89 ;FICHE ;4 ; ; ; ; ; ; ;FORMFICH
; I ;DS
X 89 ; ;FICHE01 ; ;Default

D 91 ;REPORT1 ;5 ; ; ; ; ; ;HP00 ;REPORT1

X 91 ; ; ; ;cexpand

D 92 ;REPORT2 ;5 ; ; ; ; ; ;HP00 ;REPORT2

X 92 ; ; ; ;cexpand

D 93 ;REPORT3 ;5 ; ; ; ; ; ;HP00 ;REPORT3

X 93 ; ; ; ;cexpand

D 94 ;REPORT4 ;5 ; ; ; ; ; ;HP00 ;REPORT4

X 94 ; ; ; ;cexpand

D 101 ;L253 ;5 ; ; ; ; ; ;HP00 ;L253

X 101 ; ; ; ;Default

D 134 ;L159 ;5 ; ; ; ; ; ;HP00 ;L159

X 134 ; ; ; ;Default

D 201 ;L1657 ;5 ; ; ; ; ; ;HP00 ;L1657

X 201 ; ; ; ;Default

D 326 ;L326 ;5 ; ; ; ; ; ;HP00 ;L326

X 326 ; ; ; ;Default

D 500 ;L500 ;5 ; ; ; ; ; ;HP00 ;L500

X 500 ; ; ; ;Default

D 501 ;L501 ;5 ; ; ; ; ; ;HP00 ;L501

X 501 ; ; ; ;Default

D 502 ;L502 ;5 ; ; ; ; ; ;HP00 ;L502

X 502 ; ; ; ;Default

D 503 ;L503 ;5 ; ; ; ; ; ;HP00 ;L503

X 503 ; ; ; ;Default

D 504 ;L504 ;5 ; ; ; ; ; ;HP00 ;L504

X 504 ; ; ; ;Default
---------end of second appended file--------------

---------start of third appended file-------------

#J1384 ;BATCHMAN;USER.ACCOUNT ;$STDLIST;LP ;4 ; 0; 484;22/08/02;14:46;
22/08/02;14:46;
tstb0300 ; ; ;#O29860
;LP ;#;
#J1417 ;GW106C03;USER.ACCOUNT ;$STDLIST;LP ;4 ; 0; 72;22/08/02;14:57;
22/08/02;14:57;
tstb0300 ; ; ;#O29896
;LP ;#;
#J1429 ;GW218C03;USER.ACCOUNT ;$STDLIST;LP ;4 ; 0; 108;22/08/02;14:57;
22/08/02;14:57;
tstb0300 ; ; ;#O29908

----end of third appended file and of report------------


Ygor has helped me out and this is what he came up with:

awk 'BEGIN {
FS=";"
frmt="|%-13s|%-16s|%-18s|%-10s|\n"
printf frmt, "Machine Name", "JobName/Session", "User Name", "Spool ID"
}
NR==22 {
box=$1
}
/^#J[0-9]{4}/ {
job=$2
user=$3
getline
getline
id=$4
printf frmt, box, job, user, id
} ' file1

...tested...

|Machine Name |JobName/Session |User Name |Spool ID |
|hp14 |BATCHMAN |USER.ACCOUNT |#O29860 |
|hp14 |GW106C03 |USER.ACCOUNT |#O29896 |
|hp14 |GW218C03 |USER.ACCOUNT |#O29908 |


---------------------------------------------------------

But when I try this on my POSIX system, the results are not aligned the way it should be. Is there a command I can use to align the data under its appropriate column heading?

Thanks for all the help that can be given.

 
HAve you tried this ?
frmt="|%-13.13s|%-16.16s|%-18.18s|%-10.10s|\n"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Thank you and it did work, it put my back on track, I was stuck with the alligning.

Questions:
What would you do if you had too many columns? I have more columns that I have to add to the final output report. I do like AWK and we are trying to avoid a dB due to the fact that the HP3000/MPE system will be sunset. This script can be taken with us when we transport to a HP/UX.

This is what I mean about too many colomuns, these are the names of the columns that will be in thr report.

Job Number -- JobName/Session Name -- User Name -- Spoolfile ID -- FileName -- Device -- Device Type -- Priority -- Lines -- SpoolFile Flag -- Copies -- Name of Environment file -- System -- SRC System -- SRC devie -- SRC Spool Id -- Creation Date on SRC Syste -- Creation Time on SRC System -- SpoolFile Close date -- SpooFile Close time


You seem to be very seasoned with this and your professional experience will be greatly appreciated and valued.

Thanks a million. You get a STAR..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top