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
将您的printf行更改为以下内容:
bar=$(printf ' , "%s" u ($1):($%s) lw 8 ti' ${foo[@]} "2" ${foo[@]} "3" ${foo[@]} "4" ${foo[@]} "5" )
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.