-5

How can I separate only the IP addresses from the pic below? kali screenshot

closed as unclear what you're asking by jimmij, Rui F Ribeiro, mosvy, dr01, Jeff Schaller Nov 8 '18 at 11:14

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    how much do you know about grep ? – thrig Nov 8 '18 at 3:58
  • 3
    the text could be easily extracted with any free online OCR service. – mosvy Nov 8 '18 at 5:32
  • 1
    Please use the code tag to display output like this instead of posting an image. – eyoung100 Nov 8 '18 at 8:11
2

Simply pipe it through egrep: ... | grep -E '^[.0-9]+$' will discard all lines which have anything else than dots and digits 0-9. (Yes, one could elaborate a more restrictive pattern, but the above is simple to remember and fast to type. Actually I'd even use egrep instead of grep -E but that is depreciated according to (e)grep --help.)

  • Thanks but hey If I wanted the other way around, I mean If I wanted to leave the strings and filter IP addresses? – oazed lium Nov 8 '18 at 4:20
  • Just use grep -vE : -v = --invert-match selects non-matching lines. (RTFM - i.e., see grep --help for further info! ;-)) – Max Nov 9 '18 at 6:28
1
grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' access_log

-o: Only matching string/int

-E: Extended regex, will force grep to behave more like egrep

Not the answer you're looking for? Browse other questions tagged or ask your own question.