sed awk or perl for this?

N

NNTP

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.
 
H

Helgi Briem

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.
any ideas?

I don't know sed or awk, but:

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

Ed Morton

On 9/11/2003 8:48 AM, NNTP wrote:
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.

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.
 
W

Walter Briscoe

In message <[email protected]> of Thu, 11
I have a script that outputs the following.

200 23.131.155.5;
1 23.131.161.4; [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;

any ideas?
Try to learn one of the languages whose names you know!
You're welcome. Meanwhile, you might try sed "/[0-9][0-9] /!d" < infile
 
B

Barry Kimelman

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

news8080 said:
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.

#!/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;
 
J

John W. Krahn

NNTP said:
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;


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



John
 
C

Charles Demas

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;

if the first column is always an integer:

awk '$1 > 9' infile

or for "characters" then this:

awk 'length($1) > 1' infile


Chuck Demas
 
Z

zzapper

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;

Just for the sake of diversity (amuse geule)

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

zzapper
 
A

Antony

zzapper said:
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;

Just for the sake of diversity (amuse geule)

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

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
 
V

Vlad Tepes

I don't know sed or awk, but:

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

There are shorter perl versions:

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

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

Kenny McCormack

I don't know sed or awk, but:

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

There are shorter perl versions:

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

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

Mark B

NNTP said:
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.

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
 
A

Alan Connor

I don't know sed or awk, but:

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

There are shorter perl versions:

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

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.
 
A

Alan Connor

That's fine, Alan. If there's anything else you don't understand,
feel free to share that, too.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top