我正在使用Perl在大文件中搜索特定的纬度/经度数据。但我只想要属于之前包含"GT017"的数据的经度/经度数据
我已成功获取以下数据类型呼号拉特长时间戳
但是,我似乎不能将获取的数据限制为仅与呼号 GT017 相关的纬度/经度/时间戳
我已经尝试了if语句和子例程,但似乎都不允许我只打印专门与呼号GT017相关的纬度/长度/时间戳
use strict;
#search for headers
my $find1= "GT017 ";
my $find2 = "timeStamp";
my $find3 = "latDD";
my $find4= "lonDD";
#above provides in response to my $find
#"callsign":"GT017 "
#"latDD":33.733200,
#"lonDD":-84.475667,
#"timeStamp":"2019-07-19T13:46:57.8Z",
open (NEW1, ">", "new1.txt" ) or die "could not open:$!";
open (FILE, "<", "test revab.txt") or die "could not open:$!";
while (<FILE>) {
#I want only a specific callsign's lat/long/timestamp printed
if ($find1 =~ /GT017/) {
print NEW1 if (/$find1/);
print NEW1 if (/$find2/);
print NEW1 if (/$find3/);
print NEW1 if (/$find4/);
}
}
close (FILE);
close (NEW1);
我得到一个大文件,其中包含原始文件中的每个纬度/经度/时间戳。
"latDD":33.733200,
"lonDD":-84.474266,
"timeStamp":"2019-07-19T13:46:58.22Z",
"latDD":33.733200,
"lonDD":-84.474266,
"timeStamp":"2019-07-19T13:46:58.8Z",
"latDD":33.708528,
"lonDD":-84.388506,
"timeStamp":"2019-07-19T13:46:58.33Z",
以下是我每次出现的"呼号":"GT017",
"callsign":"GT017 ",
"timeStamp":"2019-07-19T13:47:50.0Z",
"latDD":33.781071,
"lonDD":-84.401736,
下面是
一个示例:
my $find = '"callsign":"GT017 "';
while (<FILE>) {
if (/Q$findE/) {
print NEW1 $_;
for (1..3) {
print NEW1 scalar <FILE>;
}
}
}
这将打印带有呼号的行和以下 3 行。