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

Help in parsing a report 1

Status
Not open for further replies.

cstorm

MIS
Oct 1, 2001
69
US
awk Gurus,

I have a report that contains data in this format:

Server Name: acme
Description: xyz
Install Date: mm/dd/yy
Location: address

Backup Clients: server1
server2
server3
server4

Server Name: alpha
Description: xyz
Install Date: mm/dd/yy
Location: address

Backup Clients: beta1
delta37


I need an awk statement that will create the report in the following format:

Server Name: acme
Backup Clients: server1
server2
server3
server4

Server Name: alpha
Backup Clients: beta1
delta37

I just need the Server Name and its Backup Clients. Any help would be greatly appreciated.
 
awk '
/^(Server Name|Backup Clients):/
NF<=1
' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The output of PHV's ad hoc program is
[tt]
Server Name: acme

Backup Clients: server1
server2
server3
server4

Server Name: alpha

Backup Clients: beta1
delta37
[/tt]
To avoid the extra blank line:
Code:
/^Server Name:/
/^Backup Clients:/, /^ *$/
[tt]
Server Name: acme
Backup Clients: server1
server2
server3
server4

Server Name: alpha
Backup Clients: beta1
delta37
[/tt]
The line
[tt]/^Backup Clients:/, /^ *$/[/tt]
means start printing when "Backup Clients" is found and continue printing until a blank line is read.
 
Thanks to both of you. The command works great!
 
Is there an easy way to count the records found. For example, now I am told I need:

Server Name: acme
Backup Clients: server1 1
server2 2
server3 3
server4 4

Server Name: alpha
Backup Clients: beta1 1
delta37 2


Thanks for your help!
 
awk '
/^Server Name:/{i=0;print;next}
/^Backup Clients:/, /^ *$/{print $0,++i}
' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the quick reply, PH. This solved the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top