Uma maneira de usar perl
:
Conteúdo de script.pl
:
use warnings;
use strict;
## Check arguments.
die qq[Usage: perl $0 <input-file>\n] unless @ARGV == 1;
my (@alpha, @digit);
while ( <> ) {
## Omit blank lines.
next if m/\A\s*\Z/;
## Remove leading and trailing spaces.
s/\A\s*//;
s/\s*\Z//;
## Save alphanumeric fields and fields with
## only digits to different arrays.
if ( m/\A[[:alpha:]]+\Z/ ) {
push @alpha, $_;
}
elsif ( m/\A[[:digit:]]+\Z/ ) {
push @digit, $_;
}
}
## Get same positions from both arrays and print them
## in the same line.
for my $i ( 0 .. $#alpha ) {
printf qq[%s %s\n], $alpha[ $i ], $digit[ $i ];
}
Conteúdo de infile
:
AAAA
BBBB
CCCC
DDDD
1234
5678
9012
3456
EEEE
7890
Execute como:
perl script.pl infile
E resultado:
AAAA 1234
BBBB 5678
CCCC 9012
DDDD 3456
EEEE 7890