Re: [vox-tech] bash scripting question

2007-04-25 Thread Bill Broadley
Micah Cowan wrote:
> Cylar Z wrote:
>> Hey programming gurus...
>>  
>> I want to write a script which takes a block of text
>> and extracts any numbers which match a 123.456.789.012
>> pattern. I am not looking for any numbers in
>> particular (so I don't think the grep command will be
>> of much help) but rather, any set of numbers that
>> looks like an IP address. 
> 
> Why /not/ grep?
> 
> egrep -o '\<[0-9]{1,3}(\.[0-9]{1,3}){3}\>'
> 
> does a decent job, though it will match invalid components like your 456
> or 789 above. A more thorough regex could be constructed to match
> exactly 0-255, but it's somewhat painful.
> 

Heh, exactly, I was just working out similar when I saw the post.

If you do not want duplication then:
egrep -o '\<[0-9]{1,3}(\.[0-9]{1,3}){3}\>' | sort | uniq
___
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech


Re: [vox-tech] bash scripting question

2007-04-25 Thread Micah Cowan

Cylar Z wrote:

Hey programming gurus...
 
I want to write a script which takes a block of text

and extracts any numbers which match a 123.456.789.012
pattern. I am not looking for any numbers in
particular (so I don't think the grep command will be
of much help) but rather, any set of numbers that
looks like an IP address. 


Why /not/ grep?

egrep -o '\<[0-9]{1,3}(\.[0-9]{1,3}){3}\>'

does a decent job, though it will match invalid components like your 456 
or 789 above. A more thorough regex could be constructed to match 
exactly 0-255, but it's somewhat painful.


--
HTH,
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
___
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech


Re: [vox-tech] bash scripting question

2007-04-25 Thread Nick Schmalenberger
On Wed, Apr 25, 2007 at 08:28:40PM -0700, Cylar Z wrote:
> Hey programming gurus...
>  
> I want to write a script which takes a block of text
> and extracts any numbers which match a 123.456.789.012
> pattern. I am not looking for any numbers in
> particular (so I don't think the grep command will be
> of much help) but rather, any set of numbers that
> looks like an IP address. 
> 
> Basically the script is to look through some log files
> and find all of the IP numbers listed there. Having
> accomplished this, the script is to compile a list of
> the numbers it finds by redirecting the output to a
> text file. I'm planning to set this up as a
> supplemental automatic log-scanning tool that will run
> nightly as a cron job.
> 
> Could sed or awk be of use here? Not intimately
> familiar with either, but I have heard they are
> powerful text-processing tools. I can research them on
> my own if you guys think I should go that route. I'm
> sure this is a simple task but I'm too green to know
> where to start.
> 
> Your thoughts, please.
> 
> Thanks,
> Matt
> 
This thread might help you:
http://www.perlmonks.org/?node_id=395990
but you should also look at the logwatch program, I think it does a
pretty good job of generating reports for various log files.
Nick Schmalenberger
___
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech


[vox-tech] bash scripting question

2007-04-25 Thread Cylar Z
Hey programming gurus...
 
I want to write a script which takes a block of text
and extracts any numbers which match a 123.456.789.012
pattern. I am not looking for any numbers in
particular (so I don't think the grep command will be
of much help) but rather, any set of numbers that
looks like an IP address. 

Basically the script is to look through some log files
and find all of the IP numbers listed there. Having
accomplished this, the script is to compile a list of
the numbers it finds by redirecting the output to a
text file. I'm planning to set this up as a
supplemental automatic log-scanning tool that will run
nightly as a cron job.

Could sed or awk be of use here? Not intimately
familiar with either, but I have heard they are
powerful text-processing tools. I can research them on
my own if you guys think I should go that route. I'm
sure this is a simple task but I'm too green to know
where to start.

Your thoughts, please.

Thanks,
Matt

> 
___
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech