0

I am using the following lines in a script.

foo=$1

bar=$(printf  ' , "%s" u ($1):($2) lw 8 ti' ${foo[@]} ${foo[@]} ${foo[@]} ${foo[@]}   )

bar=${bar:2}

echo $bar    

This produces the following line as the value of variable bar

"rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti

Is it possible to modify the script so the output is:

"rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($3) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($4) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($5) lw 8 ti
1
  • I modified the question!!! Commented Oct 7, 2013 at 14:58

2 Answers 2

1

Change your printf line to the following :

bar=$(printf ' , "%s" u ($1):($%s) lw 8 ti' ${foo[@]} "2" ${foo[@]} "3" ${foo[@]} "4" ${foo[@]} "5" )
Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you are replacing some $2's with new strings. Insert this line before echo $bar :

bar=$(echo $bar | sed 's/$2/$5/4; s/$2/$4/3; s/$2/$3/2;')

This replaces the 4th, 3rd and 2nd occurrence of $2 with new respective values $5, $4 and $3.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.