Find the answer to your Linux question:
Results 1 to 3 of 3
I have syntax error in line (script is not mine and i use this script in more complex part): SEE HERE sed -e "s^Xtemplate^\"$fn"^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2

    Syntax error in sed command - any help


    I have syntax error in line (script is not mine and i use this script in more complex part):
    SEE HERE
    sed -e "s^Xtemplate^\"$fn"^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > temp.gs

    NOTE
    I try to gess excluding " in the midlle od $fn^g
    sed -e "s^Xtemplate^\"$fn^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > temp.gs
    NO RESULT

    Any help
    Boris

  2. #2
    Just Joined! TinoY's Avatar
    Join Date
    May 2012
    Location
    Slovakia
    Posts
    9
    I dont know the context in wich you are using the script, but when i run it it prompts me to end a quotation. It would be best to use single quotes when surounding the expressions. However i am guessing you are using this within a bash script.

    Try escaping the other ' " ' aswell. If you dont get any error message that means that the script just did not find the patterns in question.
    sed -e "s^Xtemplate^\"$fn\"^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > temp.gs

    You might want to try to split them into several sed commands by piping each result into the input of the other, and see if that gives you some output.

    Giving the context of the script might be useful since it is hard for me to guess what it is you want to do.

  3. #3
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2
    #!/bin/tcsh
    #----------------------------------------------------------------
    # note THIS IS A SCRIPT (IT IS CHAIN OF SCRIPTS AND IT IS RELATED TO METEOROLOGY)
    # oN THE BOTTOM ARE TWO LINES WITH THEIR ORIGINALS
    #
    #
    set gwdir = $EMS_UTIL/grads/products/kumar
    set wgrib = $EMS_UTIL/bin/wgrib

    #
    if ( $#argv != 2 && $#argv != 3 ) then
    echo
    echo '*********************************************'
    echo ' usage: get_plots <path to domain dir> <GrADS control file w/o path> <domain number>'
    echo '*********************************************'
    exit 1
    endif

    #
    set dn=$1
    set gd="$1/emsprd/grads"
    set ct=$2

    set no = '01'
    if ($3) set no = "$3"

    # Set the path/filename of the GrADS control file.
    #
    set fn="$gd/$2"

    #
    chdir $gwdir

    #
    echo "\n\n Running $0 to generate Web pages for domain $no\n"
    # Get the necessary variables
    #
    set ft = `grep tdef $fn | gawk '{print $2}'`
    set fx = `grep xdef $fn | gawk '{print $2}'`
    set fy = `grep ydef $fn | gawk '{print $2}'`
    set fint = `grep tdef $fn | gawk '{print $5}' | cut -c 1`
    set gf = `grep dset $fn | sed "s/\^//g" | gawk '{print $2}'`
    set gf = "$gd/$gf"

    #
    if (! -e "$gwdir/work") rm -fr $gwdir/work >& /dev/null
    mkdir -p "$gwdir/work"
    chdir $gwdir/work

    foreach fld (hgt tmp)
    rm -f ${fld}_flist >& /dev/null
    foreach lev (925 850 700 500 300 200)
    $wgrib -s $gf | grep -i ":${fld}:${lev} mb:" | $wgrib -s -nh -ncep_opn -bin -i $gf -o ${fld}_${lev}.dat >& /dev/null
    echo ${fld}_${lev}.dat >> ${fld}_flist
    end
    echo "$fx\n$fy\n$ft" > maxmin.in
    $gwdir/bin/${fld}_maxmin < maxmin.in
    rm -f maxmin.in *.dat >& /dev/null
    end

    #
    chdir "$gwdir/web"
    foreach fld (prec mslp)
    @ fts = $ft - 1
    if ($fld == 'prec') set f = 'Total Precipitation'
    if ($fld == 'mslp') set f = 'Mean Sea Level Pressure (mb)'
    rm -f ${fld}.html >& /dev/null
    mkdir $fld >& /dev/null
    sed -e "s/BBBB/$fld/g" -e "s/XXXX/$fts/g" -e "s/YYYY/$fint/g" -e "s/ZZZZ/$f/g" templates/single_lev.html > ${fld}/${fld}.html
    end

    foreach fld (hght relh vvel temp rvor wind)
    if ($fld == 'hght') set f = 'Height'
    if ($fld == 'relh') set f = 'Relative Humidity'
    if ($fld == 'vvel') set f = 'Vertical Velocity'
    if ($fld == 'temp') set f = 'Temperature \(Degrees C\)'
    if ($fld == 'rvor') set f = 'Relative Vorticity'
    if ($fld == 'wind') set f = 'Winds \(m\/s\)'
    mkdir $fld >& /dev/null
    foreach lev (200 300 500 700 850 925)
    rm -f ${lev}${fld}.html >& /dev/null
    set fd = "${lev} hPa $f"
    sed -e "s/AAAA/$lev/g" -e "s/BBBB/$fld/g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" -e "s/ZZZZ/$fd/g" templates/multi_lev.html > ${fld}/${lev}${fld}.html
    end
    end

    #
    chdir "$gwdir/work"
    ln -s $gwdir/scripts/cbarhov2.gs cbarhov2.gs >& /dev/null
    ln -s $gwdir/scripts/colors colors >& /dev/null
    foreach fld (hght temp)
    if ($fld == 'hght') set fl = 'hgt'
    if ($fld == 'temp') set fl = 'tmp'
    set uc = `echo $fl | tr '[a-z]' '[A-Z]'`
    rm -f temp.gs temp1.gs >& /dev/null
    echo " Creating Images for field: $fld"
    #ORIGINAL sed -e "s^Xtemplate^\"$fn"^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > temp.gs
    echo "s^Xtemplate^\\"$fn"^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > temp.gs
    sed -e s^Xtemplate^\$fn^g -e s/XXXX/$ft/g -e s/YYYY/$fint/g ${gwdir}/scripts/${fld}.gs > temp.gs
    foreach lev (200 300 500 700 850 925)
    set cllab=`cat $gwdir/work/${fl}_${lev}.mnx`
    sed -e "s/${lev}${uc}CLEVS/$cllab/g" temp.gs > temp1.gs
    mv temp1.gs temp.gs
    end
    gradsc -blc temp.gs >& /dev/null
    mv *.png $gwdir/web/${fld}
    rm -f temp.gs >& /dev/null
    end

    foreach fld (relh wind vvel rvor prec mslp)
    if ($fld == 'hght') set fl = 'hgt'
    if ($fld == 'temp') set fl = 'tmp'
    rm -f temp.gs >& /dev/null
    echo " Creating Images for field: $fld"
    #ORIGINAL sed -e "s^Xtemplate^\"$fn"^g" -e "s/XXXX/$ft/g" -e "s/YYYY/$fint/g" ${gwdir}/scripts/${fld}.gs > temp.gs
    sed -e s^Xtemplate^\$fn^g -e s/XXXX/$ft/g -e s/YYYY/$fint/g ${gwdir}/scripts/${fld}.gs > temp.gs
    gradsc -blc temp.gs >& /dev/null
    mv *.png $gwdir/web/${fld}
    rm -f temp.gs >& /dev/null
    end

    chdir $gwdir
    rm -fr $gwdir/work >& /dev/null

    set htmd = "$gd/d${no}htm";

    rm -fr $htmd >& /dev/null
    mkdir -p $htmd >& /dev/null
    foreach fld (relh wind vvel rvor prec mslp temp hght)
    cp -fr $gwdir/web/${fld} $htmd >& /dev/null
    end
    cp -f $gwdir/web/index.html $htmd >& /dev/null

    echo "\n View the details of your model run with:\n"
    echo " firefox file://$htmd/index.html\n\n"
    echo " End of image generation\n\n"
    exit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •