如何在 bash 循环中创建新的 netcdf 文件?

发布于 2025-01-13 21:20:03 字数 287 浏览 4 评论 0原文

我试图用 bash 循环遍历某个目录中的所有 netcdf 文件,用 NCO 操作它们,然后将结果写入新文件,所有文件都具有不同的名称。我正在考虑这样的事情:

for f in *.nc 
do ncap2 -s "vt = vt*1.3" $f2$ 
done

第二行操作变量“vt”。结果应存储在与我循环的文件名称相似的 netcdf 文件中。因此,如果原始文件名为 test.nc,我希望操作的文件名为 test_m.nc。 问题是:我应该写什么来代替 $f2$ 才能达到这个结果? 谢谢!

I am trying to loop over all the netcdf files in a certain directory with bash, manipulate them with NCO, and then write the result to new files, all with different names. I am thinking of something like this:

for f in *.nc 
do ncap2 -s "vt = vt*1.3" $f2$ 
done

The second line manipulates the variable 'vt'. The results should be stored in netcdf files with similar names as the ones that I'm looping over. So f.e., I want the manipulated file to be called test_m.nc if the original file is called test.nc.
The question is: what should I write instead of $f2$ to achieve this result?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫离伤花 2025-01-20 21:20:03

这会循环遍历文件,并将输入文件名中的字符串 foo 替换为输出文件名中的单词 bar

for f in *.nc 
do ncap2 -s "vt = vt*1.3" $f ${f/foo/bar} 
done

另一种可能性是在循环外创建一个计数器,将其递增在循环内,并将其包含在输出文件名中。

This loops over the files and replaces the string foo in the input filename with the word bar in the output filename:

for f in *.nc 
do ncap2 -s "vt = vt*1.3" $f ${f/foo/bar} 
done

Another possibility is to create a counter outside the loop, increment it inside the loop, and include it in the output filename.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文