sed awk or perl for this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NNTP

    sed awk or perl for this?

    I have a script that outputs the following.

    200 23.131.155.5;
    1 23.131.161.4;
    2 102.131.161.54;
    2 23.160.180.4;
    35 54.1.8.7;
    356 15.18.235.52;
    1 205.18.235.88;
    1 205.18.246.21;
    1 205.18.247.121;
    9 207.89.177.202;
    6 27.89.177.234;
    2 208.7.71.85;
    1 23.3.17.30;
    4 210.92.146.15;
    2 21.126.142.17;
    3 22.180.255.20;


    The first colums is the no. of time a host in column 2 has did
    something that is was not supposed to do. I only need to see hosts
    that did bad things significant times not one or two time so I am
    looking for somehthing like this.

    ../scripts.sh | <somecommand that filters and just show me lines that
    has first colum more then one char.>

    200 23.131.155.5;
    35 54.1.8.7;
    356 15.18.235.52;

    any ideas?
    Thanks.
  • Helgi Briem

    #2
    Re: sed awk or perl for this?

    On 11 Sep 2003 06:48:06 -0700, news8080@yahoo. com (NNTP) wrote:
    [color=blue]
    >The first colums is the no. of time a host in column 2 has did
    >something that is was not supposed to do. I only need to see hosts
    >that did bad things significant times not one or two time so I am
    >looking for somehthing like this.[/color]
    [color=blue]
    >any ideas?[/color]

    I don't know sed or awk, but:

    perl -e 'while (<>)
    { ($num,$ip)=spli t; next if ($num<10);print ;}' infile

    Comment

    • Ed Morton

      #3
      Re: sed awk or perl for this?



      On 9/11/2003 8:48 AM, NNTP wrote:
      <snip>[color=blue]
      > The first colums is the no. of time a host in column 2 has did
      > something that is was not supposed to do. I only need to see hosts
      > that did bad things significant times not one or two time so I am
      > looking for somehthing like this.
      >
      > ./scripts.sh | <somecommand that filters and just show me lines that
      > has first colum more then one char.>
      >
      > 200 23.131.155.5;
      > 35 54.1.8.7;
      > 356 15.18.235.52;
      >
      > any ideas?
      > Thanks.[/color]

      This will print all lines with the first columns value greater than 3, which I
      think from your opening statment is more like what you want than just looking
      for more than one char:

      awk '$1 > 3'

      Regards,

      Ed.

      Comment

      • Barry Kimelman

        #4
        Re: sed awk or perl for this?

        [This followup was posted to comp.unix.shell]

        In article <110fc16.030911 0548.7069faa5@p osting.google.c om>, news8080
        @yahoo.com says...[color=blue]
        > I have a script that outputs the following.
        >
        > 200 23.131.155.5;
        > 1 23.131.161.4;
        > 2 102.131.161.54;
        > 2 23.160.180.4;
        > 35 54.1.8.7;
        > 356 15.18.235.52;
        > 1 205.18.235.88;
        > 1 205.18.246.21;
        > 1 205.18.247.121;
        > 9 207.89.177.202;
        > 6 27.89.177.234;
        > 2 208.7.71.85;
        > 1 23.3.17.30;
        > 4 210.92.146.15;
        > 2 21.126.142.17;
        > 3 22.180.255.20;
        >
        >
        > The first colums is the no. of time a host in column 2 has did
        > something that is was not supposed to do. I only need to see hosts
        > that did bad things significant times not one or two time so I am
        > looking for somehthing like this.
        >
        > ./scripts.sh | <somecommand that filters and just show me lines that
        > has first colum more then one char.>
        >
        > 200 23.131.155.5;
        > 35 54.1.8.7;
        > 356 15.18.235.52;
        >
        > any ideas?
        > Thanks.
        >[/color]

        #!/usr/bin/perl -w

        # Read the data from STDIN

        while ( $buffer = <STDIN> ) {
        chomp $buffer;
        $buffer =~ s/^\s+//; # delete leading spaces
        @fields = split(/\s+/,$buffer);
        if ( $fields[0] > 1 ) {
        print "$buffer\n" ;
        }
        }

        exit 0;

        Comment

        • John W. Krahn

          #5
          Re: sed awk or perl for this?

          NNTP wrote:[color=blue]
          >
          > I have a script that outputs the following.
          >
          > 200 23.131.155.5;
          > 1 23.131.161.4;
          > 2 102.131.161.54;
          > 2 23.160.180.4;
          > 35 54.1.8.7;
          > 356 15.18.235.52;
          > [snip]
          >
          > The first colums is the no. of time a host in column 2 has did
          > something that is was not supposed to do. I only need to see hosts
          > that did bad things significant times not one or two time so I am
          > looking for somehthing like this.
          >
          > ./scripts.sh | <somecommand that filters and just show me lines that
          > has first colum more then one char.>
          >
          > 200 23.131.155.5;
          > 35 54.1.8.7;
          > 356 15.18.235.52;[/color]


          perl -ane'$F[0] > 9 && print' yourfile



          John
          --
          use Perl;
          program
          fulfillment

          Comment

          • Charles Demas

            #6
            Re: sed awk or perl for this?

            In article <110fc16.030911 0548.7069faa5@p osting.google.c om>,
            NNTP <news8080@yahoo .com> wrote:[color=blue]
            >I have a script that outputs the following.
            >
            > 200 23.131.155.5;
            > 1 23.131.161.4;
            > 2 102.131.161.54;
            > 2 23.160.180.4;
            > 35 54.1.8.7;
            > 356 15.18.235.52;
            > 1 205.18.235.88;
            > 1 205.18.246.21;
            > 1 205.18.247.121;
            > 9 207.89.177.202;
            > 6 27.89.177.234;
            > 2 208.7.71.85;
            > 1 23.3.17.30;
            > 4 210.92.146.15;
            > 2 21.126.142.17;
            > 3 22.180.255.20;
            >
            >
            >The first colums is the no. of time a host in column 2 has did
            >something that is was not supposed to do. I only need to see hosts
            >that did bad things significant times not one or two time so I am
            >looking for somehthing like this.
            >
            >./scripts.sh | <somecommand that filters and just show me lines that
            >has first colum more then one char.>
            >
            > 200 23.131.155.5;
            > 35 54.1.8.7;
            > 356 15.18.235.52;[/color]

            if the first column is always an integer:

            awk '$1 > 9' infile

            or for "characters " then this:

            awk 'length($1) > 1' infile


            Chuck Demas

            --
            Eat Healthy | _ _ | Nothing would be done at all,
            Stay Fit | @ @ | If a man waited to do it so well,
            Die Anyway | v | That no one could find fault with it.
            demas@theworld. com | \___/ | http://world.std.com/~cpd

            Comment

            • Walter Briscoe

              #7
              Re: sed awk or perl for this?

              In message <110fc16.030911 0548.7069faa5@p osting.google.c om> of Thu, 11
              Sep 2003 06:48:06 in comp.editors, NNTP <news8080@yahoo .com> writes
              Why post to so many groups?
              [color=blue]
              >I have a script that outputs the following.
              >
              > 200 23.131.155.5;
              > 1 23.131.161.4;[/color]
              [snip]
              [color=blue]
              >
              >The first colums is the no. of time a host in column 2 has did
              >something that is was not supposed to do. I only need to see hosts
              >that did bad things significant times not one or two time so I am
              >looking for somehthing like this.
              >
              >./scripts.sh | <somecommand that filters and just show me lines that
              >has first colum more then one char.>
              >
              > 200 23.131.155.5;
              > 35 54.1.8.7;
              > 356 15.18.235.52;
              >
              >any ideas?[/color]
              Try to learn one of the languages whose names you know!
              [color=blue]
              >Thanks.[/color]
              You're welcome. Meanwhile, you might try sed "/[0-9][0-9] /!d" < infile
              --
              Walter Briscoe

              Comment

              • zzapper

                #8
                Re: sed awk or perl for this?

                On 11 Sep 2003 06:48:06 -0700, news8080@yahoo. com (NNTP) wrote:
                [color=blue]
                >I have a script that outputs the following.
                >
                > 200 23.131.155.5;
                > 1 23.131.161.4;
                > 2 102.131.161.54;
                > 2 23.160.180.4;
                > 35 54.1.8.7;
                > 356 15.18.235.52;
                > 1 205.18.235.88;
                > 1 205.18.246.21;
                > 1 205.18.247.121;[/color]

                Just for the sake of diversity (amuse geule)

                cat xx | gvim - -c "v/^\d\d\|^[3-9]/d "

                zzapper
                --

                vim -c ":%s/^/WhfgTNabgureRIv zSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"

                http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips

                Comment

                • Antony

                  #9
                  Re: sed awk or perl for this?

                  zzapper wrote:
                  [color=blue]
                  > On 11 Sep 2003 06:48:06 -0700, news8080@yahoo. com (NNTP) wrote:
                  >[color=green]
                  > > I have a script that outputs the following.
                  > >
                  > > 200 23.131.155.5;
                  > > 1 23.131.161.4;
                  > > 2 102.131.161.54;
                  > > 2 23.160.180.4;
                  > > 35 54.1.8.7;
                  > > 356 15.18.235.52;
                  > > 1 205.18.235.88;
                  > > 1 205.18.246.21;
                  > > 1 205.18.247.121;[/color]
                  >
                  > Just for the sake of diversity (amuse geule)
                  >
                  > cat xx | gvim - -c "v/^\d\d\|^[3-9]/d "[/color]

                  That removes all addresses with a cont of 2 or below. I
                  think the OP was after

                  vim - -c "v/^\d\d/d" <xx

                  (Works on windows too :-)

                  Antony

                  --
                  vi^MicsatH AinvoNt hreUeJKr^M:map O 0fJX ~PFJX0$2hP0Oy00 ^[0"od_0@o0O

                  Comment

                  • Vlad Tepes

                    #10
                    Re: sed awk or perl for this?

                    On the CCLXXI'st day of the MMIII'rd year, Helgi Briem spoketh:
                    [color=blue]
                    > I don't know sed or awk, but:
                    >
                    > perl -e 'while (<>)
                    > { ($num,$ip)=spli t; next if ($num<10);print ;}' infile[/color]

                    There are shorter perl versions:

                    perl -ane'print if $F[0] > 10' infile

                    --
                    (,_ ,_, _,)
                    /|\`\._( )_./'/|\
                    · · \/ L /\ D · ·
                    /__|.-'`-\_/-`'-.|__\
                    `·..·´¯`·..·´¯` ·..·´¯`·..·´¯`· ..·´¯`·..·´¯`·. . ` " `

                    Comment

                    • Kenny McCormack

                      #11
                      Re: sed awk or perl for this?

                      In article <bl6p7d$qla$1@t roll.powertech. no>,
                      Vlad Tepes <minceme@start. no> wrote:[color=blue]
                      >On the CCLXXI'st day of the MMIII'rd year, Helgi Briem spoketh:
                      >[color=green]
                      >> I don't know sed or awk, but:
                      >>
                      >> perl -e 'while (<>)
                      >> { ($num,$ip)=spli t; next if ($num<10);print ;}' infile[/color]
                      >
                      >There are shorter perl versions:
                      >
                      > perl -ane'print if $F[0] > 10' infile[/color]

                      All equally off-topic in comp.lang.awk. Please take this elsewhere.
                      Thank you.

                      Comment

                      • Mark B

                        #12
                        Re: sed awk or perl for this?

                        NNTP wrote:[color=blue]
                        > The first colums is the no. of time a host in column 2 has did
                        > something that is was not supposed to do. I only need to see hosts
                        > that did bad things significant times not one or two time so I am
                        > looking for somehthing like this.[/color]

                        You don't want sed, awk, or perl!

                        You really want to see a numerically sorted list of the file
                        don't you?, i.e

                        sort -rn file

                        Then you choose to act on the first N entries as you see fit.

                        If you want to choose the worst 20 machines:

                        sort -rn file | head -20

                        Comment

                        • Alan Connor

                          #13
                          Re: sed awk or perl for this?

                          On Sun, 28 Sep 2003 13:54:54 +0000 (UTC), Vlad Tepes <minceme@start. no> wrote:[color=blue]
                          >
                          >
                          > On the CCLXXI'st day of the MMIII'rd year, Helgi Briem spoketh:
                          >[color=green]
                          >> I don't know sed or awk, but:
                          >>
                          >> perl -e 'while (<>)
                          >> { ($num,$ip)=spli t; next if ($num<10);print ;}' infile[/color]
                          >
                          > There are shorter perl versions:
                          >
                          > perl -ane'print if $F[0] > 10' infile
                          >[/color]

                          Yeh, but there's nothing short about perl.

                          Using perl for a job like this is like using a tactical nuke to dig a
                          hole in your backyard.

                          I can't for the life of me even see what the point of perl IS.

                          I see it being used for things the shell can do, but with an additional
                          700k + libs and not being suitable to replace the shell....

                          And I see it falling far short of the capabilities of the C family with
                          a compiler/assembler being 1/10 the size and using standard libs.

                          --
                          Later, Alan C
                          You can find my email address at the website:
                          elrav1.html --> ACKNOWLDEGEMENT S/CONTACT (20k or less, plain text)
                          take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a

                          Comment

                          • Alan Connor

                            #14
                            Re: sed awk or perl for this?

                            On Tue, 30 Sep 2003 03:26:52 +0000 (UTC), Vlad Tepes <minceme@start. no> wrote:[color=blue]
                            >
                            >
                            > On the CCLXXIII'rd day of the MMIII'rd year, Alan Connor spoketh:
                            >[color=green]
                            >> I can't for the life of me even see what the point of perl IS.[/color]
                            >
                            > That's fine, Alan. If there's anything else you don't understand,
                            > feel free to share that, too.
                            >[/color]

                            When you can engage your brain and treat us all to a response worthy of
                            a sentient being, feel free to do so.

                            --
                            Later, Alan C
                            You can find my email address at the website: contact.html
                            take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a

                            Comment

                            Working...