[英]find -exec with two commands (gdalinfo and jq)
我試圖在 shell 中的find
命令后連接兩個進程; 我的意圖是找到某些 GeoTiff 文件並通過從寬度*高度中減去非空計數來獲得它們的面積,第一部分在gdalinfo
中完成,然后在 json 上使用jq
完成,
我可以將它們 pipe 放在一個文件中:
gdalinfo -json -hist odm_orthophoto.tif | jq '.size[0]*.size[1]-.bands[0].histogram.buckets[0]'
但是隨着find
function 它顯然不注意第二個-exec
find. -name "odm_orthophoto.tif" -exec gdalinfo -json -hist {} \; -exec jq '.size[0]*.size[1]-.bands[0].histogram.buckets[0]' {} \;
像這樣(如果你有超過 1 個文件,這將很難連接 2 個 find -exec 命令):
find . -name "odm_orthophoto.tif" -exec bash -c '
for file; do
{
gdalinfo -json -hist "$file"
jq ".size[0]*.size[1]-.bands[0].histogram.buckets[0]" "$file"
} | tee "new_$file"
done
' -- {} +
然后:
ls -ltr new_*
請參閱使用查找
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.