如何获得我感兴趣的格式数据?

时间:2015-12-18 08:37:18

标签: perl

我的数据文件是:

060305 1932 36.72 27.7853N 56.5446E 19.27 0.00 164 0.19 MASHP0 3.64NAMDP0 3.79AGHAP0 4.50SARGP0 4.71BENGP0 5.47BANRP0 6.75 ABZAP0 6.25KALIP0 6.91

060305 2332 26.76 27.7753N 56.5629E 20.09 0.00 110 0.16 MASHP0 3.78NAMDP0 3.93AGHAP0 4.71SARGP0 4.87BENGP0 5.55JOGHP0 6.29 BANRP0 6.33ABZAP0 6.41KALIP0 7.09TIABP0 7.68MEZRP0 8.84SHARP0 10.65

我的代码:

my @date = $event =~ /(\d+\s+\d+\s+\d+\.\d+)\s\d/mg;
my @latitude = $event =~ /\s+(\d+)\.(\d+)[N]{1}\s/mg;    
my @longitude = $event =~ /\s(\d+)\.(\d+)[E]{1}\s/mg;
my @depth_rms = $event =~ /\s+(\d+\.\d+)\s+\d+\.\d+\s+\d+\s+(\d+\.\d+)\n/;
my @stations = $event =~ /( [A-Z]{4} ) ( P ) ( \d+ ) \s+ ( \d+\.\d+ ) /gx;

#my @station = substr(@stations, 0, 85, q()), "\n" while @stations;
#my $@stations[0] = $event =~ /([a-zA-Z]{4})[P]{1}+\d+\s+\d+\.\d+\d/mg;
#my $@stations[1] = $event =~ /[a-zA-Z]{4}([P]{1})+\d+\s+\d+\.\d+\d/mg;
#my $@stations[2] = $event =~ /[a-zA-Z]{4}[P]{1}+\d+\s+(\d+\.\d+\d)/mg;
#if(@stations >= $ARGV[2] && $condition[0] < $ARGV[3]) {print $output "$event", "\n" x 2};

if(@stations >= $ARGV[2]){
printf $output "%s %d%s%5.2f  %d%s%5.2f  %6.2f%6.2f\n%14s\n\n","@date", "$latitude[0]", "N", ("0." . "$latitude[1]") * 60,"$longitude[0]", "E", ("0." . "$longitude[1]") * 60,"$depth_rms[0]","$depth_rms[1]", "@stations"};

输出结果为:

060305 1932 36.72 27N47.12  56E32.68   19.27  0.19
MASH P 0 3.64 NAMD P 0 3.79 AGHA P 0 4.50 SARG P 0 4.71 BENG P 0 5.47 BANR P 0 6.75 ABZA P 0 6.25 KALI P 0 6.91

060305 2332 26.76 27N46.52  56E33.77   20.09  0.16
MASH P 0 3.78 NAMD P 0 3.93 AGHA P 0 4.71 SARG P 0 4.87 BENG P 0 5.55 JOGH P 0 6.29 BANR P 0 6.33 ABZA P 0 6.41 KALI P 0 7.09 TIAB P 0 7.68 MEZR P 0 8.84 SHAR P 0 10.65

我的目的是:

060305 1932 36.72 27N47.12  56E32.68   19.27  0.19
MASH P 0 3.64NAMD P 0 3.79AGHA P 0 4.50SARG P 0 4.71BENG P 0 5.47BANR P 0 6.75ABZA P 0 6.25KALI P 0 6.91

060305 2332 26.76 27N46.52  56E33.77   20.09  0.16
MASH P 0 3.78NAMD P 0 3.93AGHA P 0 4.71SARG P 0 4.87BENG P 0 5.55JOGH P 0 6.29BANR P 0 6.33ABZA P 0 6.41KALI P 0 7.09TIAB P 0 7.68MEZR P 0 8.84SHAR P 0 10.65

每个部分中的第二行和更多行必须包含85个字符。

您可以根据我的需要编辑我的代码吗?

0 个答案:

没有答案