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!

Reordering matched rows (and what did I do wrong?) 3

Status
Not open for further replies.

630111

MIS
Oct 30, 2001
127
US
I have an input file such as...

Client: p0691t01
Backup ID: p0691t01_1079979109
Policy: TEST_SOLARIS
Policy Type: Standard (0)
Proxy Client: (none specified)
Creator: root
Name1: (none specified)
Sched Label: Full
Schedule Type: FULL (0)
Retention Level: 1 month (3)
Backup Time: Mon Mar 22 2004 12:11:49 (1079979109)
Elapsed Time: 124 second(s)
Expiration Time: Thu Apr 22 2004 13:11:49 (1082657509)
Compressed: no
Encrypted: no
Kilobytes: 33
Number of Files: 3
Number of Copies: 1
Number of Fragments: 2
Histogram: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
DB Compressed: no
Files File Name: TEST_SOLARIS_1079979109_FULL.f
SW Version: (none specified)
Options: 0x0
MPX: 0
TIR Info: 2
TIR Expiration: Tue Mar 23 2004 12:11:49 (1080065509)
Keyword: (none specified)
Ext Security Info: no
File Restore Raw: no
Image Dump Level: 0
File System Only: no
Object Descriptor: (none specified)
Previous BI Time: Wed Dec 31 1969 18:00:00 (0)
BI Full Time: Wed Dec 31 1969 18:00:00 (0)
Request Pid: 0
Backup Status: 0

I created an awk file to extract specific information from the input file...

/^Client:/ { client=$2 }
/Sched Label:/ { sl=$3 }
/Backup Time:/ { bt=$3 " " $4 " " $5 " " $6 " " $7 " " }
/^Kilobytes:/ { kbs=$2 " " }
/Number of Files:/ { nof=$4 " " }
/Backup Status:/ { bast=$3 " " }
{ print client bt sl nof kbs bast }

I'd be happy with this...

p0691t01 Mon Mar 22 2004 12:11:49 Full 3 33 0

but instead I get this...

p0691t01
p0691t01
p0691t01
p0691t01
p0691t01
p0691t01
p0691t01
p0691t01Full
p0691t01Full
p0691t01Full
p0691t01Mon Mar 22 2004 12:11:49 Full
p0691t01Mon Mar 22 2004 12:11:49 Full
p0691t01Mon Mar 22 2004 12:11:49 Full
p0691t01Mon Mar 22 2004 12:11:49 Full
p0691t01Mon Mar 22 2004 12:11:49 Full
p0691t01Mon Mar 22 2004 12:11:49 Full33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0
p0691t01Mon Mar 22 2004 12:11:49 Full3 33 0

What did I miss?

Thanks, in advance!
630111


 
It seems changing the last line of my awk script from...

{ print client bt sl nof kbs bast }

to...

END { print client bt sl nof kbs bast }

Gave me the one line I wanted.

I'd still appreciate any comments/feedback.

Thanks!
630111
 
Assuming 'Backup Status' is the LAST line in the sequence of lines.

/^Client:/ { client=$2 }
/Sched Label:/ { sl=$3 }
/Backup Time:/ { bt=$3 " " $4 " " $5 " " $6 " " $7 " " }
/^Kilobytes:/ { kbs=$2 " " }
/Number of Files:/ { nof=$4 " " }
/Backup Status:/ { bast=$3 " "; print client bt sl nof kbs bast}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thank you, vgersh99. Unfortunately, it is in the middle of the input file. How would I change your script to take that into consideration?

Thanks!
630111
 
if there's only ONE block of records in a file, I'd do it the way you did it with printing in the 'END' section.

If your file containg more than ONE block of records , pls post a sample file to see the 'pattern'.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Because it has no pattern associated with it, the statement

{ print client bt sl nof kbs bast }

is executed for every line in the file. The statement

END { print client bt sl nof kbs bast }

is executed after all lines in the file have been read because it has the special pattern END. Is your script doing what you want? Did you try Vlad's script and does it do what you want?

CaKiwi
 
CaKiwi, thanks for the explanation and thanks for the guidance Vlad. I'm almost there.

I've looked, but cannot seem to find the proper way to format my output. The line...

END { print client bt sl nof kbs bast }

Produces...

kpmg-2n55f1fkqf Mon Mar 22 2004 19:07:25 Differential-Inc 3817 236725 0
usdalweb08 Mon Mar 22 2004 19:00:59 Differential-Inc 3152 265971 0
usdalapp17 Mon Mar 22 2004 19:00:56 Differential-Inc 3235 283062 0
ole_yeller Mon Mar 22 2004 19:07:45 Differential-Inc 2868 268635 0

How do I make this look a little cleaner, such as

bvconswd2k01 Mon Mar 22 2004 19:06:52 Differential-Inc 2476 233429 0
pma0692f00 Mon Mar 22 2004 19:00:44 Daily_Incremental 2985 18134 0
usdalcim01 Mon Mar 22 2004 19:00:54 Differential-Inc 3674 293913 0
bvconswh Mon Mar 22 2004 19:07:13 Differential-Inc 910 37242 0
bkrprdpdc01 Mon Mar 22 2004 19:00:57 Differential-Inc 796 43571 0
pma1592f00 Mon Mar 22 2004 19:00:52 Daily_Incremental 20362 104834 0

Thanks!
630111
 
Okay, that didn't line up quite as I had planned, but I hope you get the idea. Thanks!

630111
 
In the awk man page, take a look at the printf function

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Something like

printf "%-12s%4s%4s ... \n", client,bt,sl, ...

%-12s left justifies with trailing spaces , for a maximum of 12 characters, %4s right justifies. Also check out the %d format for integers.

CaKiwi
 
Changed my END line from

END { print client bt sl nof kbs bast }

to

END { printf "%-15s %-3s %-3s %-2d %-4d %-8d %-20s %-5d %-10d %-3d", client bt sl nof kbs bast }

(I think I got that right)

and now my output says

awk: not enough arguments in printf(%-15s %-3s %-3s %-2d %-4d %-8d %-20s %-5d %-10d %-3d)

Thanks!
630111
 
you have to have the MATCHING number of parameters. Pay attention how many '%s' you have in a statement and how many parameters you' passing in.

so far: you have 10 %s formats
6 parameters.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
END { printf "%-15s %-3s %-3s %-2d %-4d %-8d %-20s %-5d %-10d %-3d", client bt sl nof kbs bast }
You have 10 % in the format string, so awk expect 10 more arguments (at least) for the printf function.
That aside, you lack a \n (line terminator) at the end of the format, and, worst, the next arguments are not comma separated.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
You guys rock - a little more tweaking and I'm set.

Thanks for all your help!

630111
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top