0

I have the same issue, so I want to use wgrib2 command to extract TMP and save for each point (list of station of csv file) and I'm getting error. I'm using while do loop as below:

ifile="GSM_GPV_Rgl_I"$yyyymmddhh"_grib2.bin" #.nc4 file to read 
istnlst="/media/moza/Elements//work1/guidance/temp/Station_Table.csv" #list of lat-lon for which to extract TS
ofile="_tmp_gpv.csv"

while IFS=-,- read -r p; do
  echo -e "Reading station..... "$p
  stn=$(echo $p | cut -d ',' -f 1)
  out="/media/moza/Elements/work1/guidance/temp/gpvdata/"$yyyymmddhh"_"$stn$ofile
  lon=$(echo $p | cut -d ',' -f 2)
  lat=$(echo $p | cut -d ',' -f 3)

  wgrib2 "GSM_GPV_Rgl_I"$yyyymmddhh"_grib2.bin" \
    -match ":TMP:" -match ":24 hour fcst:|:36 hour fcst:" \
    -v p -Lon lon lat -csv > $out

  sed -i -e "/value/"$stn"/1"$ofile #replace value column name w/ stn name
  echo
done < $istnlst

The error is:

Reading station..... "Nacala",40.716,-14.466 ./station_guidance2221.sh: line 67: /media/moza/Elements/work1/guidance/temp/gpvdata/2021060300_"Nacala"_tmp_gpv.csv: Invalid argument

Reading station..... "Dindiza",33.5,-22.75 ./station_guidance2221.sh: line 67: /media/moza/Elements/work1/guidance/temp/gpvdata/2021060300_"Dindiza"_tmp_gpv.csv: Invalid argument

I need some help to solve this.

cas
  • 1
  • 7
  • 119
  • 185
  • You need to quote your variables properly. And you should probably write this in awk or perl or something instead of shell. See [Why does my shell script choke on whitespace or other special characters?](https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters) and [Why is using a shell loop to process text considered bad practice?](https://unix.stackexchange.com/q/169716/7696) – cas Jun 24 '21 at 00:36
  • out="/media/moza/Elements/work1/guidance/temp/gpvdata/"$yyyymmddhh"_"$stn$ofile lacks an even number of quotes - so its definitely wrong. If you had looked at or near line 67, you would have seen the error yourself. – Jeremy Boden Jun 24 '21 at 10:12
  • Yes. I solved that now its working I added on the wgrib2 command -ij -csv - > $out. so on the csv output its only print one line, supposed to print two line: one for 24 hour record TMP and 36 hour TMP record but its only print one, 24 hour. – Hipolito Cardoso Jun 24 '21 at 12:13

0 Answers0