in reply to Re^2: Searching for two lines that begin with the same string
in thread Searching for two lines that begin with the same string
I'll answer both your posts in one:
Please show a sample.
Please show a sample.
Your sample data doesn't contain duplicates. This does:
10.35.15.64/29 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.15.96/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.2.128/25 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.24.192/26 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.24.48/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.128/25 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.32/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.48/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.64/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.80/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.26.0/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.32/28 10.133.3.11 OSPF-EXT1 3 if-illnevera +nswerquestionsagain-10.133.3.11 10.35.26.16/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.26.192/26 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.26.32/27 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.26.64/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.26.96/27 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.8.128/27 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.8.192/27 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.9.128/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11
If I run my snippet unaltered, I get
10.35.25.32/28 10.133.3.11 OSPF-EXT1 3 if-servermgm +t.cntx03-servermgmt-10.133.3.11 10.35.25.32/28 10.133.3.11 OSPF-EXT1 3 if-illnevera +nswerquestionsagain-10.133.3.11
It outputs pairs: the previous and the current match. So if you have 3 lines starting with the same CIDR notated IP address, you'll get 4 lines back for that match. With 4 lines matching, you get 6 lines: 3 pairs.
<update>
perl -ne '/^(\S+)/;if($S{$1}){print$S{$1}unless$s{$1}++;print}$S{$1}=$ +_' file
outputs just 4 lines for 4 matches.
</update>
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Searching for two lines that begin with the same string
by tgrossner (Novice) on Dec 18, 2006 at 19:36 UTC | |
by shmem (Chancellor) on Dec 18, 2006 at 21:06 UTC |