[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [TEKNIK] bash - grep og regular expression



On Wed, 22 Mar 2006 12:39:12 +0100
"Mogens Melander" <sslug@sslug> wrote:

> Hejsa,
> 
> Dagens opgave går ud på, i bash-script, at trække ip-adressen ud af
> følgende log entries.
> 
> Mar 19 12:45:48 styx sshd[19796]: Failed password for illegal user
> newsroom from 213.133.99.19 port 33561 ssh2 Mar 19 12:45:48 styx
> sshd[19797]: Illegal user brian from 213.133.99.19
> 
> Regulære udtryk har aldrig været min stærke side, og jeg har en klar
> fornemmelse af at denne opgave løses bedst af sådanne. Jeg kan klare
> det med en kombination af grep|cut, men er overbevist om at det kan
> klares enklere/mere elegant med det rette udtryk.
> 

Med grep (egrep) kan det f.eks. gøres sådan her:

egrep 'sshd.* Failed password for illegal'
fil_der_skal_undersøges|egrep -o -e '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'


Med sed kan en løsning være:

 sed -e '/\(.*sshd.* Illegal user .* \)\(.*\)/!d' -e
's/.* \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)/\1/g' fil_der_skal_undersøges

Mvh
Jesper K. Pedersen


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-04-01, 02:02 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *