Operating System - HP-UX
1833827 Members
2062 Online
110063 Solutions
New Discussion

Parsing File line 1, 2, 3, 4 (repeating) into field1, field2, field3 via awk

 
SOLVED
Go to solution
Kevin_31
Regular Advisor

Parsing File line 1, 2, 3, 4 (repeating) into field1, field2, field3 via awk

I'm trying to get Clay's awk program to work for me for similar reasons as in the thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=100049

I'm lookin into writing some scripts which give me a webpage that is updated daily. It'll list the backups, with red/green,etc along each one. Then for each backup session, you can click on a hotlink to open a page which shows the full session messages from "omnidb -session xxxx/xx/xxx -report" and maybe another hotlink to see which tape it wrote to. I'll probably integrate this with our BigBrother setup.

Anyway, attached is the output from when I ran the awk script like above:

omnidb -rpt | tail -50 | awk -f parse.awk

parse.awk says:

BEGIN {
prev2=""
prev1=""
}
{
printf("%s\t%s\t%s\n",prev2,prev1,$0)
}
prev2 = prev1
prev1 = $0

Instead of "rogress" for in progress, I need everything.

Cheers Heroes!

3 REPLIES 3
Elmar P. Kolkman
Honored Contributor
Solution

Re: Parsing File line 1, 2, 3, 4 (repeating) into field1, field2, field3 via awk

The problem is that the check in rogress resulted in not every line being printed. But what you could do is something like this:

BEGIN { prev1="";prev2="";prev3="" }
{
if (NF < 1) {
if (prev1 != "") {
printf("%s\t%s\t%s\n",prev3,prev2,prev1);
}
prev3="";
prev2="";
prev1="";
} else {
prev3=prev2;
prev2=prev1;
prev1=$0;
}
}
Every problem has at least one solution. Only some solutions are harder to find.
Graham Cameron_1
Honored Contributor

Re: Parsing File line 1, 2, 3, 4 (repeating) into field1, field2, field3 via awk

The original script contains a pattern, which if matched, prints out that line and the 2 preceding, with tabs between each.
You have taken out the pattern, so for every line in the source, you are getting the line and the 2 preceding.
I don't have omnidb, so I don't know your input format, but I hope that explains what you are seeing.
When you say you need "everything", what patterns does this represent?
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Kevin_31
Regular Advisor

Re: Parsing File line 1, 2, 3, 4 (repeating) into field1, field2, field3 via awk

G: thanks, that makes perfect sense as to why I was getting garbage (dd if=garbage of=garbage)

K: cheers, I've taken your great awk script and added two more variables/fields and now I have exactly what I want! I'll add that to my armory of awk scripts (which I understand enough to use, not explain) and I'll crack on with My BigBrother/OmniBack integration!

thanks loads!