Reputation: 21
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!
Upvotes: 0
Views: 340
Reputation: 6322
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.
Upvotes: 1