Sed Awk Cut Grep Combination Help ?

I have been reading for a few hours trying to educate myself enough to accomplish this task, so please know I have performed some research. Unfortunately, I am not a *NIX scripting expert, or a coder. I come from a network background instead.

SO, here is my desired outcome. I have some Cisco CSS boxes I am trying to organize data off of into a more useful format for mass migrations. I will give some sample of my raw / formatted data, and the way I would like to end up formatting it.

Here is the data (there are literally hundreds of the following data blocks in a text file. I have also changed the IP, and name for protection):

Name: vcstest019-asdfghjkl-9-www Index: 51
Type: Local State: Down
Rule ( 10.1.1.9 ANY ANY )
Session Redundancy: Disabled
Redirect Domain:
Redirect String:
Keepalive: (HTTP-80:HEAD: 5 3 5 )
Keepalive Error: Not reachable failure
Keepalive Encryption: Disabled
Last Clearing of Stats Counters: 03/03/2009 00:24:17
Mtu: 1500 State Transitions: 0
Total Local Connections: 0 Total Backup Connections: 0
Current Local Connections: 0 Current Backup Connections: 0
Total Connections: 0 Max Connections: 65534
Total Reused Conns: 0 Weight Reporting: None
Weight: 1 Load: 255

What I *WANT* to grab from it is the Name, State and Total Connections number. I accomplished this via "grep -e Name -e "Total Connections" -e Type data

However, that will display it as such:

Name: vcstest004-asdfghjkl-2-direct Index: 2
Type: Local State: Suspended
Total Connections: 0 Max Connections: 65534
Name: vcstest004-asdfghjkl21-2-https Index: 3
Type: Local State: Suspended
Total Connections: 0 Max Connections: 65534

What I really WANT this to look like, is something like this:

Name: vcstest004-asdfghjkl-2-direct State: Suspended Total Connections: 0
Name: vcstest004-asdfghjkl21-2-direct State: Suspended Total Connections: 0

I am not sure how to parse through the data to yield the desired result.

Now, to FURTHER complicate things, I want to take a SECOND set of data and add it into the mix, correlating the information.

###################

The second data set will look something like this (again, with hundreds, if not thousands of entries, and some of the names have been changes/ips, etc..)

content vcstest013-asdf-3-www
add service vcstest019-szvmHELLO-2-www
vip address 10.10.1.3
protocol tcp
port 80
active

content vcstest013-asdf1-4-www
add service vcstest019-szaloha225-3-www
vip address 10.10.1.4
protocol tcp
port 80
active

content vcstest013-asdf2-5-www
add service vcstest019-szwowser225-4-www
vip address 10.10.1.5
protocol tcp
port 80
active

content vcstest019-agh-3-https
add service vcstest019-szjeemonie225-2-https
vip address 10.10.1.3
port 443
protocol tcp
active

The "service" identifier, matches up with the "content" identifier right above it. SO.... At the end of the day, I would like something to provide me with the following information:

CONTENT Information
Service Information
What is the current State? (from first file)
WHat is the number of Total Connections? (from first file)

I hope this makes sense. I'm just not sure how to further narrow down the amount of data. I'm just grabbing the information off of the devices and dumping them to text files. I *REALLY* do appreciate anyone's help here. I have been working on this for a few hours, but am at a loss.

Two questions:

  1. How are the paragraphs in the first file separated? By blank lines?

  2. How do the two files relate to each other: name in the first file matches content or service in the second one?

  1. There will be a blank carriage return inbetween the paragraphs.

  2. The NAME (in the first one) matches Service (in the second)

Thanks for your quick response.

Use nawk or /usr/xpg4/bin/awk on Solaris:

awk 'NR == FNR {
  /Name/ && n = $2
  /Local State/ && _[n] = $NF
  /Total Connections/ && _[n] = _[n] FS $3
  next
  }
/content/ { c = $2 }
/service/ && $NF in _ {
  split(_[$NF], t)
  print "CONTENT", c
  print "Service", $NF
  print "What is the current State?", t[1]
  print "What is the number of Total Connections?", t[2] RS
  }' file1 file2  

I will try that first thing tomorrow morning when I get back to work. Thank you so VERY!!! much for the help!! This could potentially save me at least 50 hours worth of manual work, and headache! :smiley: :b::b::b::b:

If your awk version supports the sub() string function *and* if your record always have the same layout, here is another way of doing it:

awk  'BEGIN{RS="\n\n"; FS="\n"}{sub(/^.+State/, "State", $2); sub(/Max.+$/, "", $14); print $1,$2,$14}' file

Or, if you hate the one-liner style of coding:

awk  '
BEGIN{
	RS="\n\n"
	FS="\n"
}
{
	sub(/^.+State/, "State", $2)
	sub(/Max.+$/, "", $14)
	print $1,$2,$14
}' file

Edit: By reading the OP, I just realized that I stopped at the first request. So, go for the Radoulov's snippet. I can't think of anything better.