in reply to Re: Searching for two lines that begin with the same string
in thread Searching for two lines that begin with the same string

Just printing each line 2x
  • Comment on Re^2: Searching for two lines that begin with the same string

Replies are listed 'Best First'.
Re^3: Searching for two lines that begin with the same string
by shmem (Chancellor) on Dec 18, 2006 at 17:29 UTC

    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}
      "if-illnevera +nswerquestionsagain-10.133.3.11" - theres no reason to get indignant, it just didnt work for me. I am not calling you out, or anything. you will notice i bumped your rating while you went and stomped down on mine. <sigh> Check this out though...
      [tgrossne@sl6archive1:SavvisCustom, 01:26 PM, Mon Dec 18]>cat routes.t +xt | wc 3940 13780 311528 [tgrossne@sl6archive1:SavvisCustom, 01:26 PM, Mon Dec 18]>perl -ne '/^ +(\S+)/;if($S{$1}){print$S{$1}unless$s{$1}++;print}$S{$1 }=$_' routes.txt | wc 3939 13778 311505
      Not sure why it does this for me...
        it just didnt work for me.

        Sorry for the rant mode of my previous post, but it just didn't work is just the type of answers that get me tempered. Never mind. I didn't "stomp down on yours" ;-)

        Regarding your word count - what's in 'routes.txt' ? Is this file consistent with your sample? Is the first char really a non-blank? Is the first sequence of non-blanks a CIDR notated IP address?

        --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}