I am trying to replace the value of a character variable (say Times) in some multiple nc files.
I can do that for one file like this: ncap2 -O -s 'Times(0,:)="2020-01-05_00:00:00";' file.nc file.nc
I want to automate this over all the files, but each file has a different value for the Times variable. For each file, I get the value from the file name and store it in a variable (not in the nc file) say newval. Then I perform the operation above in a loop.
Dear all,
I am trying to replace the value of a character variable (say Times) in some multiple nc files.
I can do that for one file like this:
ncap2 -O -s 'Times(0,:)="2020-01-05_00:00:00";' file.nc file.ncI want to automate this over all the files, but each file has a different value for the Times variable. For each file, I get the value from the file name and store it in a variable (not in the nc file) say newval. Then I perform the operation above in a loop.
I tried this but it didn’t work for me:
I would appreciate any help with this.
Thanks
Derrick
This appears to be a quoting issue. Try
Thank you for your response!
I tried and got the following error:
Command-line script:1:22: unexpected token: _00
Be persistent, and notice the clues in the error message. Try
ncap2 -O -s "Times(0,:)=\"${newval}\"" file.nc file.ncThis works! I appreciate your help.