Re: extracting an IPv4 address from text?
- In reply to: Robert Huff : "extracting an IPv4 address from text?"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 04 Apr 2022 14:08:44 UTC
Dear Robert, Robert Huff <roberthuff@rcn.com> writes: > Hello: > Let's suppose I want to parse a line from auth.log and extract > the IP address (if any) to stdout. > (...thanks...) #+BEGIN_SRC python # -*- coding: utf-8 -* import re p = re.compile("\ [1-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]") FPATH = "auth.log" # you can edit here f = open(FPATH, "r") data = f.read() f.close() result = p.findall(data) # <class 'list'> if __name__ == "__main__": print(result) print(len(result)) #+END_SRC It is python3 script, thanks! Sincerely, Byung-Hee -- ^고맙습니다 _白衣從軍_ 감사합니다_^))//