Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run a script using sed i runing like this

for et in   1 # 2 3

      if [ -d ET$et ]; then rm -rf ET$et; fi

        mkdir ET$et
        cd ET$et
        cp  $home/step_$i/FDE/diabatA/run.adf .
        cp  $home/step_$i/FDE/diabatA/mas$ .

        awk1=`awk '/type=fde/{print NR }' run.adf | head -1`
        awk2=`$(echo "$a+379" | bc -l )`
       sed -n "$awk1,"$awk2"p" run.adf > first

        awk3=`awk '/ATOMS/{print NR +1}' first`
        awk4=`cat mas$ | wc -l`
        awk4=$( echo "$awk4-1" | bc -l )
        awk5=`awk "/ATOMS/{print NR +"${awk4}" }" run.adf`
        sed -n "$awk3,"$awk4"p" first > atoms

        par=$( echo "$awk4-99" | bc -l )
        rho1=$(cat atoms | head -34 )
        rho2=$(cat atoms | head -64 | tail -31)
        rho3=$(cat atoms | head -97 | tail -33)
        rhoall=$(cat atoms | tail -${par} )

        echo -e "$rho1\n$rho2\n$rhoall" > eje

but is telling me this:

(standard_in) 1: syntax error
sed: -e expression #1, char 6: unexpected `,'
sed: -e expression #1, char 1: unknown command: `,'

Please, I appreciate any help with this issue...

Thanks Pablo

share|improve this question

The unknown command ',' means that either $awk1 or $awk3 is empty. Instead of a line number, the first thing sed sees is a comma.

You need to do something if "run.adf" does not contain /type=fde/ or /ATOMS/

I highly recommend using better variable names: "awk1" does not convey to the reader that it contains a line number.

Your quoting could be more readable: sed -n "${awk1},${awk2}p"

share|improve this answer

Both your sed expressions look malformed... here's the first:

sed -n "$awk1,"$awk2"p" run.adf > first

I would suggest you're actually looking for:

sed -n "s/$awk1/$awk2/p" run.adf > first

And alter the second one similarly.

sed -n "s/$awk3/$awk4/p" first > atoms
share|improve this answer
Thanks, However is telling me : (standard_in) 1: syntax error sed: -e expression #1, char 7: unknown command: /' sed: -e expression #1, char 3: unknown command: 2' Do you have any suggestion? Thanks again – Pablor Nov 5 '13 at 15:51
Yeah, that's my bad. See the updated version. – Oli Nov 5 '13 at 15:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.