Search code examples
regexunixfiltermirc

Grep ip's and hostnames from a Mirc log


I need to filter out all of the hostnames / ip's that have joined my server.

I have a log file, but I don't know what regex I could use, I have already tried searching here.

Maybe you can help me out?

Log:

03[22:56] * Jason (~Jason@33-33-33-33.rev.sfr.net) has joined #talk
03[22:56] * NotJason (~NotJason@12.34.22.22) has joined #talk

Solution

  • May be you should try this:

    (?<=@).+?(?=\))
    

    . matches any character

    + one or more time

    ? make it non greedy i.e search will stop at first occurence

    ?= positive lookahead(look for ) and stop)

    Update:

    With grep it will be like this

    grep -o -P  '(?<=@)(.+?)(?=\))' logfile > file2
    

    ?<= is positive look behind(look for @ behind).

    -o will print only matched part.

    -P perl-regexp(PATTERN is a Perl regular expression)