Help with regex to match an IP
I have output in this format:
(?@94.21.54.x) I want list just the IP's, what is the command to do that? I tired this: cat file.txt | sed '/^[0-9].*$/!d' But it didn't work. TIA |
Edit: wrong
|
Quote:
Match, as the only thing on the line, a single digit, followed by any number of characters. What book or reference have you been using for BASH and scripting? This will match an IP, but it is not perfect: Code:
([0-9][0-9]?[0-9]?\.){3}[0-9][0-9]?[0-9]? This works also (slightly shorter): Code:
([0-9]([0-9]?){2}\.){3}[0-9]([0-9]?){2} |
If you want to remove all the rubbish from around the IP Address, like the "(?@" and the ")", then either of the following should do what you want:
cat file.txt | awk '{ gsub("^.*@|)$","",$0); print $0 }' cat file.txt | sed -r 's/^.*@|\)$//g' Hope this helps. Thanks, Paul. |
Quote:
23.4.56.7 124.6.7.98 etc. the last one says: match exactly 4 occurences of (a single digit followed by an optional character) It will match: 1a3b4c7h---and a zillion other combos.... |
I'm dumb, forgot my {1-3}s..
|
All times are GMT -5. The time now is 01:26 AM. |