如何将字母行的文本与shell中的数字行合并?

NWS*_*NWS 10 scripting shell-script text-processing regular-expression merge

我有一个包含如下文本的文件:

AAAA
BBBB
CCCC
DDDD

1234
5678
9012
3456

EEEE 

7890
Run Code Online (Sandbox Code Playgroud)

等等...

我想将字母行与数字行匹配起来,所以它们是这样的:

AAAA 1234 
BBBB 5678
CCCC 9012
DDDD 3456

EEEE 7890
Run Code Online (Sandbox Code Playgroud)

有谁知道实现这一目标的简单方法?

Bir*_*rei 3

一种使用方法perl

内容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 ];
}
Run Code Online (Sandbox Code Playgroud)

内容infile

AAAA
BBBB
CCCC
DDDD

1234
5678
9012
3456

EEEE 

7890
Run Code Online (Sandbox Code Playgroud)

像这样运行它:

perl script.pl infile
Run Code Online (Sandbox Code Playgroud)

结果:

AAAA 1234
BBBB 5678
CCCC 9012
DDDD 3456
EEEE 7890
Run Code Online (Sandbox Code Playgroud)