wildcards with selvar
Added by Sylvaine Ferrachat over 12 years ago
Hi,
In the context of HAMMOZ output, we encounter huge list of variables containing common parts in names (e.g.: ddep_SO4_NS, ddep_SO4_KS, ddep_SO4_AS, ddep_SO4_CS). It would be very useful to get the possibility to use basic wildcards to select variables that obey a certain pattern in name (e.g. selvar,ddep_SO4_*). Even better, full regexp implementation in the selvar operator would be terrific!
Sylvaine
Replies (3)
RE: wildcards with selvar - Added by Jaison-Thomas Ambadan over 12 years ago
Hi,
Suppose I've a file with variables var1, var11, var22, var33, and var111, and if I want to select var11,var22,var33; you could try:
cdo -selvar,var$?$? ifile ofile
Hope this helps!
Cheers,
J.
RE: wildcards with selvar - Added by Jaison-Thomas Ambadan over 12 years ago
Hi again,
I think the above trick works only in some "trivial" cases - sorry But I'm sure there must be some workaround
Cheers,
J.
RE: wildcards with selvar - Added by Sylvaine Ferrachat over 12 years ago
Hi,
Well, there's indeed some bash workarounds but it's rather cumbersome:
e.g., for extracting all vars with name starting with 'emi_DU':
#!/bin/bash set -e infile=XYZ.nc vars=`cdo showvar $infile 2> /dev/null | sed -e 's/\s/\n/g' | \ sed -n -e '/^emi_DU/p' | tr '\n' ',' ` vars=${vars%%,} cdo selvar,$vars ...
that's why it would be very handy to have it already available in cdo...
Cheers
Sylvaine