in reply to reformat log files
If the ip address at the end is separated by a known character from the rest of the line, say a space, then:
use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); my $s = ' '; # Separator say s/\A(.*)$s(.+)\Z/$2$s$1/r for split /\n/, <<'END'; djshajfh kjwhjhfh aks81368`17`tr `" " \ 12.123.12.001 fueiwqgfh 9ur`023456789-ds 10.1.999.002 fdfhfsdh she eq3435235b ^&*(O&*()^&*( 10.20.30.40 fdfhfsd1111.11.11.11hheq3435235b ^&*(O&*()^&*( 1.2.3.4 fdfhfsdhheq341111.3333.4444.11.2235235b ^&*(O&*()^&*( 111.222.333.444 END
Produces
12.123.12.001 djshajfh kjwhjhfh aks81368`17`tr `" " \ 10.1.999.002 fueiwqgfh 9ur`023456789-ds 10.20.30.40 fdfhfsdh she eq3435235b ^&*(O&*()^&*( 1.2.3.4 fdfhfsd1111.11.11.11hheq3435235b ^&*(O&*()^&*( 111.222.333.444 fdfhfsdhheq341111.3333.4444.11.2235235b ^&*(O&*()^&*(
|
|---|