I've got a bash variable containing several lines of text, which includes IP addresses, and I need to remove 'everything' before the last IP address occurrence in the same line.
This:
43.12.40.53 [email protected] archery-666.foobar.com 66.77.11.44 data test@example 55.32.39.153 [email protected] 5.113.30.37 dummy 89-109-22-006.static.example.com.br 89.109.22.6 [email protected] 68.28.15.55 68.28.15.55 another should be transform into:
43.12.40.53 [email protected] 66.77.11.44 data test@example 55.32.39.153 [email protected] 5.113.30.37 dummy 89.109.22.6 [email protected] 68.28.15.55 another Reading this post How can I delete everything until a pattern and everything after another pattern from a line? I tried:
var=$(sed 's/^.*\(([0-9]{1,3}[\.]){3}[0-9]{1,3}\).*$/\1/' <<< "$var") but it doesn't work.