Need help with AWK..

Hello all,

This is what the goal is:

Sample File 1:

hp14
#J3010 ;SPOOL ;UNISPOOL.SYS ;$STDLIST;LP ;4 ; 0; 198;18/07/02;17:37;18/07/02;:42;
tstb0300 ; ; ;#O27756 ;LP ;#;
#J3339 ;SR261C03;MANAGER.SYS ;$STDLIST;LP ;4 ; 0; 72;18/07/02;17:38;18/07/02;18:42;
tstb0300 ; ; ;#O28112 ;LP ;#;
#J3340 ;SR214C03;MANAGER.SYS ;$STDLIST;LP ;4 ; 0; 1773;18/07/02;17:41;18/07/02;18:42;
tstb0300 ; ; ;#O28113 ;LP ;#;
#J3342 ;SR260C03;MANAGER.SYS ;$STDLIST;LP ;4 ; 0; 131;18/07/02;17:43;18/07/02;18:43;
tstb0300 ; ; ;#O28115 ;LP ;#;

End of File Sample 1_____________

What I need help on is getting certain items in the above file sample report into another report that will be legible and under their appropriate columns. Note that I have associated the data from the above sample report to where the columns (they will be columns in the final report) are next to the column titles below. Example, Number 1 below is Job Number this will be a column in the final report and under this column, I need to have #J7258 under it and so on..

The output file will have these columns in it:

  1. Job Number = (#J7258)
  2. Job Name = (GW268D08)
  3. User Name = (MGR.MRSHIC08)
  4. File Name = ($STDLIST)
  5. Device = (LP)
  6. Device Type = (4)
  7. Priority = (0)
  8. Lines = (8)
  9. Creation Date On SrcSystem = (07/31/04)
  10. Time = (00:59)
  11. Date Close = (07/31/04)
  12. Time Close = (01:00)
  13. Src System = (mrsh0800)
  14. System = ( ) on the above report this is left blank but not always.
  15. Spool Flag = ( ) on the above report this is left blank but not always.
  16. Spool File ID = (#0394809)
  17. Src Device = (LP)
  18. Src Spool Id = (#03948097)

------------end----------------------------------------

This is what I have so far and it isn't working too well.. If you can help, that would be greatly appreciated..

----code snipit---------------------------------------

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

-----end of script snipit---------------------------

Hope this message makes sense, please ask if it doesn't. Again, all help will be greatly appreciated..

This is just a quick hack, but try something like

awk -v FS=';' 'BEGIN {printf ( "%-10s\t%-10s\t%-10s\n", "Job Number", "Job Na
me", "User Name") } {printf( "%-10s\t%-10s\t%-10s\n", $1, $2, $3 )}' inputfile

This example only processes the first three fields, so you'll need to expand this to use all your fields. Also put the awk in a script, 'cos this one-liner is a bit long and unmanageable.

The output you'll get is....

Job Number      Job Name        User Name
#J3010          SPOOL           UNISPOOL.SYS
#J3339          SR261C03        MANAGER.SYS
#J3340          SR214C03        MANAGER.SYS
#J3342          SR260C03        MANAGER.SYS

Change the formatting to suit your needs.

Edit: Looking at your source data above, it looks like each record is spread across two lines? If so, pipe through paste to get the two lines concatenated before processing.

e.g.

paste - - < inputfile | awk -v FS=';' -f awkscript

Also, if you don't want that top line (hp14) to be processed, use

sed '1d' inputfile | paste - - | awk -v FS=';' -f awkscript

instead.

Cheers
ZB

Simplify the original code to...

awk 'BEGIN {
   FS=";"
   frmt="|%-13s|%-16s|%-18s|%-10s|\n"
   printf frmt, "Job Number", "JobName", "User Name", "File Name"
}
/^#J[0-9]{4}/ {
   printf frmt, $1, $2, $3, $4
} ' file1

Tested on the sample data...

|Job Number   |JobName         |User Name         |File Name |
|#J3010       |SPOOL           |UNISPOOL.SYS      |$STDLIST  |
|#J3339       |SR261C03        |MANAGER.SYS       |$STDLIST  |
|#J3340       |SR214C03        |MANAGER.SYS       |$STDLIST  |
|#J3342       |SR260C03        |MANAGER.SYS       |$STDLIST  |