I have a file that looks like this:
abuse@verizon.net abuse@verizon.net 100.0.9.181
abuse@verizon.net abuse@verizon.net 100.1.147.27
abuse@verizon.net abuse@verizon.net 100.32.40.7
abuse@universal.net.id abuse@universal.net.id abuse@universal.net.id 101.0.7.77
abuse@republictelecom.com.sg 101.100.177.191
abuse@cnc-noc.net abuse@cnc-noc.net abuse@cnc-noc.net 101.17.155.18
abuse@telstra.net 101.174.11.146
abuse@telstra.net 101.174.2.218
I'd like to use sed
(or awk
) to manipulate the file so that everything after the first space and up to (but not including the space before) the first occurrence of a number is removed. So the above would end up looking like this:
abuse@verizon.net 100.0.9.181
abuse@verizon.net 100.1.147.27
abuse@verizon.net 100.32.40.7
abuse@universal.net.id 101.0.7.77
abuse@republictelecom.com.sg 101.100.177.191
abuse@cnc-noc.net 101.17.155.18
abuse@telstra.net 101.174.11.146
abuse@telstra.net 101.174.2.218
I've tried:
sed '/\s.*$\([0-9]\)/\1/g' <filename>
sed '/\s.*$/,/0-9/p' <filename>
sed '/\s.*$/,/\(\[0-9\]\)/p' <filename>
and many other combinations of examples I've found on the Web. I think the problem may be that sometimes the line is already as I want it; other times there are two or more extra email addresses between the first email address and the ip address.
Edit: I will always want the first email address occurring on a line (sometimes there is only one; other times there are more than one), and everything else on the line removed up until the space before the IP address at the end. I need to keep a space between the email address and the IP address. If the line contains only one email address and the IP address, I'd like to leave it alone.
Can anyone (please) help?