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 gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK Store Line for later use

Status
Not open for further replies.

bRANT55

Technical User
Mar 12, 2014
2
0
0
US
I have log file containing a large amount of unformatted text.
I want to take the top text from my log file and append a job id from the text below it.

Stream Client Group DataSet Name Type Size Time Exitcode
------ -------------------- -------------------- ------------------------------------------------------------ --------- ------------------- --------- --------
1 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
2 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
3 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
4 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
5 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
6 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
7 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
8 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
9 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
10 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
11 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
12 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
13 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
14 XSERVER2 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
15 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
16 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
17 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
18 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
19 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
20 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0
21 XSERVER3 ALL 0000000000000000000000000000000000000000 Archive 000000000000000 00000000 0



Stream Job# Status: Description
------ ------ -----------------------------------------------------------------
1 11111 0: the requested operation was successfully completed

Stream Job# Status: Description
------ ------ -----------------------------------------------------------------
2 22222 0: the requested operation was successfully completed

------ ------ -----------------------------------------------------------------
3 33333 0: the requested operation was successfully completed



My desired output would contain text from the upper and lower text blocks.
For example.

1|XSERVER3|ALL|0000000000000000000000000000000000000000|Archive|000000000000000|00000000|0|11111
2|XSERVER3|ALL|0000000000000000000000000000000000000000|Archive|000000000000000|00000000|0|22222
3|XSERVER3|ALL|0000000000000000000000000000000000000000|Archive|000000000000000|00000000|0|33333



can I accomplish this with awk?
 
A starting point:
Code:
awk '$2=="Job#"{++j}/^[1-9]/{if(j)print x[$1]"|"$2;else{x[$1]=$0;gsub(/ /,"|",x[$1])}}' /path/to/logfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH. Got me a lot closer than I was. :)
Output did result in a lot of extra pipes. Any idea why?
Also could you break down the syntax to help me understand.
Thanks again!
 
Output did result in a lot of extra pipes
Seems like there are a lot of contiguous spaces.
Replace this:
[pre]gsub(/ /,"|",x[$1])[/pre]with this:
[pre]gsub(/ */,"|",x[$1])[/pre]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top