如何在 bash 循环中创建新的 netcdf 文件?
我试图用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会循环遍历文件,并将输入文件名中的字符串
foo
替换为输出文件名中的单词bar
:另一种可能性是在循环外创建一个计数器,将其递增在循环内,并将其包含在输出文件名中。
This loops over the files and replaces the string
foo
in the input filename with the wordbar
in the output filename:Another possibility is to create a counter outside the loop, increment it inside the loop, and include it in the output filename.