我必须更改几百个文件的标题,将vdate从标题中添加到标题中。
如果nc文件的名称为rerun4_spindown_19971222.nc,则vdate = 19971222
我知道我可以通过ncdump -h filename找到vdate (参见下面的示例头)。
ncdump -h rerun4_1997_spindown_09191414_co2
netcdf rerun4_1997_spindown_09191414_co2 {
dimensions:
lon = 768 ;
lat = 384 ;
nhgl = 192 ;
nlevp1 = 96 ;
spc = 32896 ;
// global attributes:
:file_type = "Restart history file" ;
:source_type = "IEEE" ;
:history = "" ;
:user = " Linda" ;
:created = " Date - 20190919 Time - 134447" ;
:label_1 = " Atmospheric model " ;
:label_2 = " Library 23-Feb-2012" ;
:label_3 = " Lin & Rood ADVECTION is default" ;
:label_4 = " Modified physics" ;
:label_5 = " Modified radiation" ;
:label_6 = " Date - 20190919 Time - 134447" ;
:label_7 = " Linda " ;
:label_8 = " Linux " ;
:fdate = 19950110 ;
:ftime = 0 ;
:vdate = 19971222 ;
:vtime = 235800 ;
:nstep = 776158 ;
:timestep = 120. ; 但是,我必须手动打开所有文件并手动更改文件的标题.数以百计的文件。我更喜欢做一个可以自动实现的bash。
我相信一定有一种更聪明的方法从nc头中提取vdate,你们能帮我吗?
谢谢!
发布于 2019-10-02 14:23:00
从理论上讲,这样的事情应该有效:
#! /bin/sh
for file in rerun4_*_spindown_* ; do
vdate=$(ncdump -h $file | awk '$1 == ":vdate" { print $3 }')
new_name="rerun4_spindown_$vdate.nc"
mv "$file" "$new_name"
done我无法访问netCDF文件-需要更多的测试。
https://stackoverflow.com/questions/58186182
复制相似问题