Sponsored Content
Special Forums UNIX and Linux Applications Infrastructure Monitoring Print "From: To:" Row Only On First Ocurrence Post 302411165 by durden_tyler on Wednesday 7th of April 2010 09:31:17 PM
Old 04-07-2010
Here's a Perl one-liner that should do the job:

Code:
perl -lne 'print if !/^From/ or (/^From/ and $_ ne $p); $p=$_ if /^From/' your_file

Test run -

Code:
$ 
$ cat firewall.rules
From:  Wlan       To:    Untrust-Firn
567   | Any                       | State Auditor VPN         | grp-vpn                   | Permit          | alw-state-vpn

From:  Wlan       To:    Untrust-Firn
594   | Any                       | Any                       | GRE                       | Permit          | alw-vpn   
      |                           |                           | grp-vpn                  

From:  DMZ-public To:    VPN-cs    
506   | Polycom-COB-2320          | aaaaaaaaa-Polycom         | H.323                     | Permit          | alw-polycom
      |                           |                           | PING                     
      |                           |                           | Polycom-Call-Setup       

From:  DMZ-public To:    VPN-cs    
517   | Polycom-BB-ConfRm         | aaaaaa-Polycom            | ANY-4hrs                  |                 | alw-polycom

From:  Trust-cs   To:    VPN-cs    
351   | Any                       | Any                       | Any-to-8-hrs              | Permit          |           
      |                           |                           | PING                     

From:  Trust-cs   To:    Wlan      
426   | grp-trust-dhcpservers     | Any                       | DHCP-Relay                | Permit          | alw-dhcp  

From:  Trust-cs   To:    Wlan      
436   | Any                       | Any                       | PING                      | Permit          | alw-ping  
      |                           |                           | SSH                      

From:  Trust-cs   To:    Wlan      
510   | abcd-epicenter.primary.ad | Guest-Router              | SNMP                      | Permit          | alw-snmp  
      | netmon.noc.xxxx.xxx       |                           |
$ 
$ 
$ # Run the Perl one-liner
$ perl -lne 'print if !/^From/ or (/^From/ and $_ ne $p); $p=$_ if /^From/' firewall.rules
From:  Wlan       To:    Untrust-Firn
567   | Any                       | State Auditor VPN         | grp-vpn                   | Permit          | alw-state-vpn

594   | Any                       | Any                       | GRE                       | Permit          | alw-vpn   
      |                           |                           | grp-vpn                  

From:  DMZ-public To:    VPN-cs    
506   | Polycom-COB-2320          | aaaaaaaaa-Polycom         | H.323                     | Permit          | alw-polycom
      |                           |                           | PING                     
      |                           |                           | Polycom-Call-Setup       

517   | Polycom-BB-ConfRm         | aaaaaa-Polycom            | ANY-4hrs                  |                 | alw-polycom

From:  Trust-cs   To:    VPN-cs    
351   | Any                       | Any                       | Any-to-8-hrs              | Permit          |           
      |                           |                           | PING                     

From:  Trust-cs   To:    Wlan      
426   | grp-trust-dhcpservers     | Any                       | DHCP-Relay                | Permit          | alw-dhcp  

436   | Any                       | Any                       | PING                      | Permit          | alw-ping  
      |                           |                           | SSH                      

510   | abcd-epicenter.primary.ad | Guest-Router              | SNMP                      | Permit          | alw-snmp  
      | netmon.noc.xxxx.xxx       |                           |
$ 
$ 
$

HTH,
tyler_durden
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. UNIX for Dummies Questions & Answers

Meaning of $var->{"@$row[0]"}=" "; ???

while (my $row = $sth->fetchrow_arrayref) { $var->{"@$row"}=" "; } Can anyone help me understanding above mentioned. i) As per my knowledge $row is taking ARRAY Refernce from the database ii) @$row is containing the value of 0th index of the array, testted the same. but I am not able... (0 Replies)
Discussion started by: jaigs_27
0 Replies

3. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

4. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

7. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies
APF(1)							      General Commands Manual							    APF(1)

NAME
apf - easy iptables based firewall system SYNOPSIS
apf DESCRIPTION
This manual page documents briefly the apf command. This manual page was written for the Debian distribution because the original program does not have a manual page. Advanced Policy Firewall (APF) is an iptables (netfilter) based firewall system designed around the essential needs of today's Internet deployed servers and the unique needs of custom deployed Linux installations. The configuration of APF is designed to be very informative and present the user with an easy to follow process, from top to bottom of the configuration file. The management of APF on a day-to-day basis is conducted from the command line with the 'apf' command, which includes detailed usage information and all the features one would expect from a current and forward thinking firewall solution. OPTIONS
apf follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -s|--start load all firewall rules -r|--restart stop (flush) & reload firewall rules -l|--list list all firewall rules -t|--status output firewall status log -e|--refresh refresh & resolve dns names in trust rules -a <HOST CMT|--allow <HOST COMMENT> add host (IP/FQDN) to allow_hosts.rules and immediately load new rule into firewall -d <HOST CMT|--deny <HOST COMMENT> add host (IP/FQDN) to deny_hosts.rules and immediately load new rule into firewall -u <HOST>|--remove <HOST> remove host from [glob]*_hosts.rules and immediately remove rule from firewall -o|--ovars output all configuration options COPYRIGHT
Copyright (C) 1999-2007, R-fx Networks <proj@r-fx.org> Copyright (C) 2007, Ryan MacDonald <ryan@r-fx.org> This program may be freely redistributed under the terms of the GNU GPL This manual page was written by Giuseppe Iuculano <giuseppe@iuculano.it>, for the Debian project (but may be used by others). August 17, 2008 APF(1)
All times are GMT -4. The time now is 04:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy