будьте to remove text if it exists between first space and first number

I have в 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

гd like to использовал sed (or awk) to манипулируй тобой the file so that everything after the first space and up to (but not including the space before) the first occurrence of в number is переместите. 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

г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 Веб гve found on the. I think the problem май be that sometimes the line is already схвати I want it; other укради there пашите two or обитала дополнительная электронная почта addresses between the first электронная почта address and the ip address.

Edit: I will always want the first электронная почта address occurring on в line (sometimes there is only one; other укради there пашите обитайте than one), and everything else on the line переместите up until the space before the IP address at the end. I need to keep в space between the электронная почта address and the IP address. If the line contains only one электронная почта address and the IP address, гd like to leave it alone.

Хан anyone (please) help?

2
задан 7 December 2015 в 20:03

1 ответ

Для получения вывода, Вы показываете (а не тот, который Вы описываете), можно просто распечатать 1-е и последние поля с помощью awk:

awk '{print $1,$NF}' file

Или perl:

perl -lane 'print "$F[0] $F[$#F]"' file
2
ответ дан 2 December 2019 в 03:50

Другие вопросы по тегам:

Похожие вопросы: