1

I am new in UNIX and I want to apply the CDO (Climate Data Operator) "remapbil" command in order to transform the grid (from a projection to geographical coordinate system). it works perfectly fine for 1 single file with the following command:

cdo remapbil,target.grd hurs_EUR-11_ICHEC-EC-EARTH_rcp26_r3i1p1_DMI-HIRHAM5_v1_day_20360101-20401231.nc hurs_36_40_bil.nc

But I have to do it for a lot of different files. For this reason, I have tried to write the following bash shell that will allow me to run the remapbil command for all file i have in my directory:

#!/bin/bash

for i in *.nc;
do
echo $i
for file in "ls *.nc"; do
cdo remapbil,target.grd tas_EUR-11_ICHEC-EC-EARTH_rcp45_r3i1p1_DMI-HIRHAM5_v1_day_20210101-20251231.nc > tas_$i_bil.nc
done
done

But i always get the following Error:

cdo remapbil (Abort): Too few streams specified! Operator needs 1 input and 1 output streams.

Can probably someone help me, that would be great

sourcejedi
  • 50,249
C.Utz
  • 11

1 Answers1

0

The for file in "ls *.nc"; do . . . ; done will run the command once, with literal argument ls *.nc - as you can confirm as follows:

$ ls *.nc
bar.nc  foo.nc
$ for file in "ls *.nc"; do echo "$file" ; done
ls *.nc

You presumably intended a command substitution using backticks in place of double quotes but that would be a bad idea1 and is unnecessary since you are already looping over the files using a (safe if quoted) shell glob. So:

for i in *.nc;
do
echo $i
cdo remapbil,target.grd  "$i" > "tas_${i}_bil.nc"
done

If you want to remove and replace the extension in the output file, you can change "tas_${i}_bil.nc" to "tas_${i%.nc}_bil.nc"


  1. Why not parse ls?
steeldriver
  • 81,074
  • thanks for your respond, but the command which has to executed must have to format like: (cdo remapbil,>targetgrid> ) otherwise it doesn´t work. Therefor i have different inputfiles and one fixed targetgrid in a different format, so the bash should do it for every single file in the directory. But unfortunately it doesn´t – C.Utz Nov 23 '17 at 15:51
  • @C.Utz apologies - see edit – steeldriver Nov 23 '17 at 15:54
  • Thank you so much, it worked perfektly well for my problem. – C.Utz Nov 27 '17 at 09:23