[英]using bash script on csv - awk and for loop
I have csv file for every day in a month, and the csv file has global point data.我有一个月中每一天的 csv 文件,csv 文件有全局点数据。 I am trying to crop each csv based on latitudinal and longitudinal extents, and export those csvs.
我正在尝试根据纬度和经度范围裁剪每个 csv,并导出这些 csv。 Here is what I tried for 5 days in a month.
这是我在一个月内尝试了 5 天的内容。
for f in ./VBD_npp_d20190[1-5]*.csv; do
awk '{for(i=$4>=3.070359 && i=$4<=40.926137 && i=$5>=107.159444 && i=$5<=128.204291){printf "%s ",$i;} print ""}' "$f" > "$f".new;
done
This dd not work.这个 dd 不起作用。
$4
and $5
columns have the latitudes and longitudes listed. $4
和$5
列列出了纬度和经度。
Please advise where I am going wrong.请告知我哪里出错了。
Thanks,谢谢,
Tilo蒂洛
Trying to do it with a "for"?试图用“for”来做到这一点? Interesting approach, but not what I'd have ever come up with.
有趣的方法,但不是我想出的。 Much easier to us one (or more if statements)
一个(或多个 if 语句)对我们来说更容易
pseudo code伪代码
{
if ($4 > minLat && $4 < maxLat && $5 > minLon && $5 < maxLon)
{
print
}
}
edit: in fact looks like you might have just a typo for
instead of if
?编辑:实际上看起来你可能只是拼写错误
for
不是if
? (not quite, you'd remove the redundant i=
bits and change the print (不完全是,您将删除多余的
i=
位并更改打印
for f in ./VBD_npp_d20190[1-5]*.csv; do
# TODO: Modify the print to use $4 (and $5 ?) instead of $i
awk '{if($4>=3.070359 && $4<=40.926137 && $5>=107.159444 && $5<=128.204291){printf "%s ",$i;} print ""}' "$f" > "$f".new;
done
This finally worked -这终于奏效了-
for i in./VBD_npp_d201901*_global*.csv;do o= basename $i global_noaa_ops_v23.csv
china_noaa_ops_v23.csv; for i in./VBD_npp_d201901*_global*.csv;do o=
basename $i global_noaa_ops_v23.csv
global_noaa_ops_v23.csv china_noaa_ops_v23.Z6837CB5FE755 head -1 $i > $o;头 -1 $i > $o; awk -F, '{if ($4>=3.07 && $4<=40.93 && $5>=107.16 && $5<=128.20) print;}' $i>> $o;done
awk -F, '{if ($4>=3.07 && $4<=40.93 && $5>=107.16 && $5<=128.20) print;}' $i>> $o;done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.