Sponsored Content
Special Forums UNIX and Linux Applications Infrastructure Monitoring Processing records as group - awk Post 302370828 by baskar on Thursday 12th of November 2009 01:45:59 PM
Old 11-12-2009
Thanks for quick update.

I'm working with a file that does not have fixed field numbers, some records have additional name and value. I want to make single line from each set ex: from policy to exit, then I want to print the value of id, name, address(multiple addresses) by finding the pattern (id, name ..etc)

awk '/policy/,/exit/{ if($0~/exit/) ORS="\n"; else ORS=" "; print}' input > tmp

I want to read tmp and find next word (value) of matched pattern (id, name, etc)



first record
policy glb id 1233 name Permit ping from "One" to "Second" "Address1" "Any" "ICMP-ANY" permit
policy id 1233
service "snmp-udp"
exit
second record
policy id 1234 name Permit ping from "One" to "Second" address "Address1" "Any" "ICMP-ANY" permit
policy id 1234
address "xyzabc"
address "12345"
service "snmp-udp"
exit

Expected output:

id name from to address service
1234 Permit Ping One Second Address1 snmp-udp
1234 Permit Ping One Second xyzabc snmp-udp
1234 Permit ping One Second 12345 snmp-udp

Last edited by baskar; 11-12-2009 at 11:45 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK Multi-Line Records Processing

I am an Awk newbie and cannot wrap my brain around my problem: Given multi-line records of varying lengths separated by a blank line I need to skip the first two lines of every record and extract every-other line in each record unless the first line of the record has the word "(CONT)" in the... (10 Replies)
Discussion started by: RacerX
10 Replies

2. UNIX for Dummies Questions & Answers

processing records in a file

Hi, I have a file that contains some records that I would like to process each line that I am interested in. My goal is to create a new file that contains only the rest_of_line for each line that matches. It has the following File Format command, platform, rest_of_line" I am searching the... (2 Replies)
Discussion started by: CAGIRL
2 Replies

3. Shell Programming and Scripting

command to group records

hi, i have records like this supplier,product, persons involved 10,150,ravi@yahoo.com 30,200,ravi@yahoo.com 20,111,payal@gmail.com 40,211,ravi@yahoo.com i want to write a command which displays values like this 10,30,40,ravi@yahoo.com for ravi@yahoo.com if there are n number of... (7 Replies)
Discussion started by: trichyselva
7 Replies

4. Shell Programming and Scripting

how to group records in a file

hi, I have records like this D127@dm.com,127,569,BRAD,25/08/2009 23:59 D127@dm.com,127,569,BRAD,25/08/2009 23:59 D159@dm.com,159,1170,DAVE,25/08/2009 23:59 D159@dm.com,159,1181,HALE,25/08/2009 23:59 D393@dm.com,393,1209,CAPIT,25/08/2009 23:59 D457@dm.com,457,571,NORTT,25/08/2009 23:59... (4 Replies)
Discussion started by: trichyselva
4 Replies

5. UNIX for Dummies Questions & Answers

keeping last record among group of records with common fields (awk)

input: ref.1;rack.1;1 #group1 ref.1;rack.1;2 #group1 ref.1;rack.2;1 #group2 ref.2;rack.3;1 #group3 ref.2;rack.3;2 #group3 ref.2;rack.3;3 #group3 Among records from same group (i.e. with same 1st and 2nd field - separated by ";"), I would need to keep the last record... (5 Replies)
Discussion started by: beca123456
5 Replies

6. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

7. Shell Programming and Scripting

Looping through records in db and processing them in UNIX

Hi, I want to read multiple records from oracle database table and then based on each record I need to do some file modifications in UNIX. I'm not sure how do I process each record from DB in UNIX.Below is the code snippet. sqlplus user/pwd@DEV for i IN (select * from table) loop -- for... (2 Replies)
Discussion started by: prats_7678
2 Replies

8. UNIX for Beginners Questions & Answers

Awk: group multiple fields from different records

Hi, My input looks like that: A|123|qwer A|456|tyui A|456|wsxe B|789|dfgh Using awk, I am trying to get: A|123;456|qwer;tyui;wsxe B|789|dfgh For records with same $1, group all the $2 in a field (without replicates), and all the $3 in a field (without replicates). What I have tried:... (6 Replies)
Discussion started by: beca123456
6 Replies

9. Shell Programming and Scripting

To group records in the file in UNIX

Hi All, I am using RHEL 6.9. I got a requirement to group the records in a file.The file content as shown below. #### FAILED JOBS IN XXX ##### 1> ABCD failed in the project XXX 2> HJK Job is in compiled state in the project XXX 3> ILKD failed in the project XXX 4> DFG failed in the... (5 Replies)
Discussion started by: ginrkf
5 Replies
selinux-policy-upgrade(8)				      System Manager's Manual					 selinux-policy-upgrade(8)

NAME
selinux-policy-upgrade - upgrade the modules in the SE Linux policy database from a policy package SYNOPSIS
selinux-policy-upgrade DESCRIPTION
selinux-policy-upgrade this command will upgrade all policy modules (including the base modules) for to the versions that are under /usr/share/selinux/SELINUXTYPE SEE ALSO
selinux(8), sestatus(8), selinuxenabled(1), load_policy(8), semodule(8), postfix-nochroot(8), check-selinux-installation(8), selinux-con- fig-enforcing(8), http://wiki.debian.org/SELinux - More about SELinux Debian install, http://etbe.coker.com.au/tag/selinux/ - Russell's SE Linux blog posts. AUTHOR
This program and it's man page was written by Russell Coker <russell@coker.com.au> for the Debian system (but may be used by others). Per- mission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-3. selinux-policy-upgrade(8)
All times are GMT -4. The time now is 01:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy