Gawk - to extract values from multi lined file -I


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk - to extract values from multi lined file -I
# 1  
Old 11-12-2012
Question Gawk - to extract values from multi lined file -I

Hi,
Request your help in getting help with the below text formatting using awk. I am still learning awk and your help here is appreciated. Thanks in advance.

Desireoutput
----------------
Code:
Virtual Pool Destination Profile Profile Profile Profile
1. virtual-1 pool-1 212.254.110.174:https profile-a-1 profile-b-1 profile-c-1 profile-d-1
2. virtual-2 pool-2 212.254.110.179:https profile-a-2 profile-b-2 
3. virtual-3 <NA> 212.254.110.169:http profile-a-3 profile-b-3
4. virtual-4 pool-4 212.254.110.169:https profile-a-4 profile-b-4 profile-c-4
5. virtual-5 pool-5 212.254.110.168:https profile-a-5 profile-b-5 profile-c-5

Sample Text:
--------------
Code:
}
virtual virtual-1 {
snatpool dmz122.168.104SNAT
pool pool-1
fallback persist sourceaddr
destination 212.254.110.174:https
ip protocol tcp
profiles
profile-a-1
profile-b-1
profile-c-1
profile-d-1
}
virtual virtual-2 {
snatpool dmz122.168.104SNAT
pool pool-2
fallback persist sourceaddr
destination 212.254.110.179:https
ip protocol tcp
profiles
profile-a-2
profile-b-2
}
virtual virtual-3 {
destination 212.254.110.169:http
ip protocol tcp
rules httptohttpsredirect
profiles
profile-a-3 
profile-b-3
}
virtual virtual-4 {
snatpool dmz192.168.104SNAT
pool pool-4
fallback persist sourceaddr
destination 212.254.110.169:https
ip protocol tcp
profiles
profile-a-4 
profile-b-4
profile-c-4
}
virtual virtual-5 {
snatpool dmz192.168.104SNAT
pool pool-5
fallback persist sourceaddr
destination 212.254.110.168:https
ip protocol tcp
profiles
profile-a-5 
profile-b-5
profile-c-5
}


Last edited by Scrutinizer; 11-13-2012 at 01:30 AM.. Reason: Code tags + changed icode tags to code tags
# 2  
Old 11-13-2012
This should work:
Code:
$ nawk '/\}/{if(v){printf ++i". "v" "p" "d;for(l in a){printf " "l;delete a[l]}};printf "\n";getline;v=$2;p=d="N/A"}/^pool/{p=$2}/^destination/{d=$2}/^profile-/{a[$1]}' file
1. virtual-1 pool-1 212.254.110.174:https profile-b-1 profile-c-1 profile-d-1 profile-a-1
2. virtual-2 pool-2 212.254.110.179:https profile-a-2 profile-b-2
3. virtual-3 N/A 212.254.110.169:http profile-a-3 profile-b-3
4. virtual-4 pool-4 212.254.110.169:https profile-a-4 profile-b-4 profile-c-4
5. virtual-5 pool-5 212.254.110.168:https profile-a-5 profile-b-5 profile-c-5

This User Gave Thanks to Subbeh For This Post:
# 3  
Old 11-14-2012
Thank you Subbeh.
Please find the actual file attached and request your helping tweaking the code as few of the parameters are not printing. Highlighted are the text I want to extract from the sample file

Code:
}
virtual traditional.abc.com_VIP_443 {
   snatpool dmz192.168.104_SNAT
   pool traditional.abc.com-pool-111
   fallback persist source_addr
   destination 16.20.110.144:https
   ip protocol tcp
   profiles
      http_traditional.abc.com_profile
      traditional.abc.com_clientssl
      oneconnect
      tcp-lan-optimized-Custom
         serverside
      tcp-wan-optimized-Custom
         clientside
   persist traditional.abc.com-cookie
}
virtual traditional.abc.com_VIP_80 {
   snatpool dmz192.168.104_SNAT
   destination 16.20.110.144:http
   ip protocol tcp
   rules http_to_https_redirect
   profiles
      http_traditional.abc.com_profile
      oneconnect
      tcp-lan-optimized-Custom
         serverside
      tcp-wan-optimized-Custom
         clientside
}
virtual international.abc.com_VIP_443 {
   snatpool dmz192.168.104_SNAT
   pool international.abc.com-pool-111
   fallback persist source_addr
   destination 16.20.110.149:https
   ip protocol tcp
   profiles
      http_international.abc.com_profile
      international.abc.com_clientssl
      oneconnect
      tcp-lan-optimized-Custom
         serverside
      tcp-wan-optimized-Custom
         clientside
   persist international.abc.com-cookie
}

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by pratheeshp; 11-14-2012 at 08:46 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick and easy way to comment out multi lined print statements

Is there a quick and easy way to comment out multi lined print statements? something like this? printf("3408 strings_line_tokens %s \n", strings_line_tokens); (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Find and extract values from one file and update other

Gents, Kindly can you help me to update a file extracting the data from other file. I have: file1 The key in this file is substr($0,4,21), and I need to update the columns 6 and 7 using the information for file2. S 21133.00 21535.00 1 0 919088.8 1843754.5 ... (2 Replies)
Discussion started by: jiam912
2 Replies

3. Shell Programming and Scripting

Extract values from multi lined url source

Hello, I want extract multi values from multi url source to a csv text. Thank you very much for help. my curl code : curl "http://www.web.com/cities//city.html Source code: div class="clear"></div> <table class="listing-details"> <tr> ... (1 Reply)
Discussion started by: hoo
1 Replies

4. Shell Programming and Scripting

Gawk - to extract values from multi lined file

Hi, I am new to awk and trying to extract some specific fields from the a large file. Can you please help me to write gawk code displaying the out put in the below format: Desired Output: name fallback_ip member member www-trymps.extlb.plstry.com-pool-1 180.254.112.50 ... (4 Replies)
Discussion started by: pratheeshp
4 Replies

5. Shell Programming and Scripting

Extract values from an XML File

Hi, I need to capture all the attributes with delete next to it. The source XML file is attached. The output should contain something like this below: Attributes = legacyExchangeDN Action = Delete Username = Hero Joker Loginid = joker09 OU =... (4 Replies)
Discussion started by: prvnrk
4 Replies

6. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

7. Shell Programming and Scripting

Sorting multi-column values from a specific file

Hi, all. I need a shell script which gathers data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: cnnturk dot... (4 Replies)
Discussion started by: canimsin
4 Replies

8. UNIX for Dummies Questions & Answers

Extract Unique Values from file

Hello all, I have a file with following sample data 2009-08-26 05:32:01.65 spid5 Process ID 86:214 owns resources that are blocking processes on Scheduler 0. 2009-08-26 05:32:01.65 spid5 Process ID 86:214 owns resources that are blocking processes on Scheduler 0. 2009-08-26... (5 Replies)
Discussion started by: simonsimon
5 Replies

9. Shell Programming and Scripting

to extract specific values twice in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values twice as shown in the example like 12345,12345.xml 04567,04567.xml 12134,12134.xml Please advice!! In the formus one of... (7 Replies)
Discussion started by: techmoris
7 Replies

10. Shell Programming and Scripting

Extract values from log file

I would like to write a shell script that will parse through a file similar to the sample below. The data in the file is redirected from rsync into a log file. I would like to call a shell script to parse through and pick out the number beside the percent sign inside the parentheses in the last... (5 Replies)
Discussion started by: wdympcf
5 Replies
Login or Register to Ask a Question