Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

for et in   1 # 2 3
    do

      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$i.xyz .

        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$i.xyz | 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
done

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
add comment

2 Answers 2

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
add comment

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 –  Pablo Ramos Nov 5 '13 at 15:51
    
Yeah, that's my bad. See the updated version. –  Oli Nov 5 '13 at 15:56
add comment

Your Answer

 
discard

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.