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!

Looking for some suggestions. 1

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
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------------


The question is: Does anybody have an idea on how I can put this in a report. The report should look liket this:

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

The above are actual Heading Columns that I would like to use in final outpul file. How can I create this with the above Heading Names?

Also, can I pars through three in one file and place information from the three in one file and place them in their respective columns in the final report?

What should I use awk, sort, cut, grep?

Any ideas how one would tackle this? Suggestions are much needed.

Thanks..
 
Any chance you could post expected result from your 3 example input files ?
I guess awk should be a good starting point.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I am not sure what the example file will look like since I am not at a starting point. I am trying to determin if I should put all all this information in a database for form purposes.

I will try to explain what the output file may look like.

Final Output File:
---------------------------------------------------------
|Machine Name | JobName/Session | User Name | Spool ID |
|--------------------------------------------------------
| HP14 BATCHMAN USER #O29860 |
--------------------------------------------------------

The report may look something like the above, but have more columns in it to identify as much information as I can from the three in one report.

The columns will be labled with these:

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


I will have to extract data (Job Number, JobName/Session--etc) from the three in one file and place them in the final report under the appropriate columns.

Can this be done with a Unix script?


 
Hi,
I am quite sure that this can be done with a Unix script. But nevertheless I would prefer a database.
This is what databases have been invented for.
regards
 
You could also say that this is what the pattern-directed scanning and processing language "awk" was invented for. For your consideration...

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...
[tt]
|Machine Name |JobName/Session |User Name |Spool ID |
|hp14 |BATCHMAN |USER.ACCOUNT |#O29860 |
|hp14 |GW106C03 |USER.ACCOUNT |#O29896 |
|hp14 |GW218C03 |USER.ACCOUNT |#O29908 |[/tt]
 
Ygor,

You have given me hope, I will try this and may comeback with some other questions, but I will feed off of your template and see what I can do. THANKS SO MUCH..

I was trying to avoid a database.

Again, thanks a million.
 
The results I get are different than the above:

|MachName |JobName/Ses |UserName |SpoolID |
|#P001A:lp=P001:sd=LPD3K.SYS:qt=text:|;SPOOL |;UNISPOOL.SYS |;4
|
|#P001A:lp=P001:sd=LPD3K.SYS:qt=text:|;SR214C03;USER.SYS|;$STDLIST;LP |;
4 |
|#P001A:lp=P001:sd=LPD3K.SYS:qt=text:|;NP644C03;USER.TRNTIC03|;$STDLIST;LP |
;4 |
|#P001A:lp=P001:sd=LPD3K.SYS:qt=text:|;GX129C03;USER.TRNTIC03|;$STDLIST;LP |
;4 |

I am not sure how to gather the meat (certain parts of the data within the 3 in 1 report) of the data and place the data under there appropriate columns.?.?

Also, If I were to add more columns, will this wrap?
 
I think you are getting different results because both the code and the data are different from that which has been posted. For example, if the field separator is set like this FS=";" then I would not expect to see any semi-colons in the output.

You must be using a different input file to the one you posted because there seems to be no resemblance between the input and output data. Perhaps you could post the one you are using? It would seem that seem that my assumption that the machine name is on line 22 is wrong, so perhaps change...

NR==22 {
box=$1
}

...to something like...

/Miscellaneous configuration items/ {
i=split($0,a," ")
box=a
}

To "gather the meat", I guess you will have to use pattern-matching and perhaps even multi-dimensional arrays. But rather than having me explain everything take a look at Sed & Awk. There is also an awk forum right here on Tek-Tips for specific problems.

 
Ygor,

Thanks, I will try the pattern matching.

Where in a script would you place the pattern matching? Before your template suggestion (Before "awk BEGIN")?

Could I perfrom pattern mathes and output that to a temp file and input that temp file back into a final output file? How would the input know how to put the data into the correct filed and under the correct column? What type of direction or placement logic would I use?

 
man awk

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm afraid that I don't have the time to describe how to structure an awk script, how to handle files, how to manipulate data and format it. Try the link instead or search the web for awk user guides. If you don't have the time to learn awk then I suggest that you try using the programming languages that you already know.
 
Thanks.

I was just looking for a starting point and you Ygor, you gave me one.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top