一种使用方式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 ];
}
内容infile
:
AAAA
BBBB
CCCC
DDDD
1234
5678
9012
3456
EEEE
7890
像这样运行:
perl script.pl infile
结果:
AAAA 1234
BBBB 5678
CCCC 9012
DDDD 3456
EEEE 7890
emacs
..您是否正在寻找elisp
解决方案,或者如何在emacs中运行shell脚本?