Sponsored Content
Top Forums Shell Programming and Scripting Sed Awk Cut Grep Combination Help ? Post 302294591 by abbzer0 on Thursday 5th of March 2009 12:51:37 PM
Old 03-05-2009
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.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed, grep, cut or combine?

I am a beginner at shell scripting, actually i am working on my first script right now. Anyway i have searched the world how to grep two letters from each word (it will always just be two words). For example: Example Blablabla I want my script to cut out Ex (from the first word) and Bl... (4 Replies)
Discussion started by: maskot
4 Replies

2. Shell Programming and Scripting

cut sed grep or other?

Hi Is there a way to cut the last two characters off a word or number given that this word or number can be of varying length? I have tried something like TEST=`echo $OLD | cut -c 1-5` where $OLD is a variable containing a number like 1234567 which gives a result of 12345. This is fine... (4 Replies)
Discussion started by: rleebife
4 Replies

3. Shell Programming and Scripting

cut in sed/awk

Hi Can i have an example where i should be able to cut columns (like for eg cut -c 1-3) in sed or awk. Regards Dhana (12 Replies)
Discussion started by: dhanamurthy
12 Replies

4. UNIX for Dummies Questions & Answers

Awk/sed solution for grep,cut

Hi, From the file "example" with lines like below, I need the int value associated with ENG , i.e, 123 SUB: ENG123, GROUP 1 SUB: HIS124, GROUP 1 .. .. Normally , i do grep ENG example | cut -d ' ' -f 2 | cut -c 4-6 Is it possible to do it in simpler way using awk/sed ? ... (5 Replies)
Discussion started by: priyam
5 Replies

5. Shell Programming and Scripting

Using grep and cut within awk

Hi My input file looks like as follows: say a.txt "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss... (5 Replies)
Discussion started by: bittoo
5 Replies

6. Shell Programming and Scripting

Advice using cut & echo combination commands

Hi, I am cutting data from a fixed length test file and then writing out a new record using the echo command, the problem I have is how to stop multiple spaces from being written to the output file as a single space. Example: cat filea | while read line do field1=`echo $line | cut -c1-2` ... (6 Replies)
Discussion started by: dc18
6 Replies

7. Shell Programming and Scripting

GREP/CUT/AWK to Arrays

hi people, I have a text file containing data, seperated by TAB. I want to process this tab'ed data as variable. how can I assign this? Ex: Code: 11aaa 12000 13aaa 14aaa 15aaa 16aaa 17aaa 21aaa 22000 23aaa 24aaa 25aaa 26aaa 27aaa 31aaa 32000 33aaa 34aaa 35aaa 36aaa 37aaa... (1 Reply)
Discussion started by: gc_sw
1 Replies

8. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

9. UNIX for Dummies Questions & Answers

Print/cut/grep/sed/ date yyyymmdd on the filename only.

I have this filename "RBD_EXTRACT_a3468_d20131118.tar.gz" and I would like print out the "yyyymmdd" only. I use this command below, but if different command like cut or print....etc. Thanks ls RBD_EXTRACT* | sed 's/.*\(........\).tar.gz$/\1/' > test.txt (9 Replies)
Discussion started by: dotran
9 Replies
All times are GMT -4. The time now is 11:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy