I am trying to append to the first line the value of a variable within a loop so, in each iteration the line growth. I am trying
sed -i '1s/.*/& $(echo "T$(echo "$j-3" | bc -l)_S$k")/' T_iSlicesExtraction_2.csv
so, I am trying to add the value of $(echo "T$(echo "$j-3" | bc -l)_S$k") to the first line. but I am having an issue "scaping" the different special characters, and I am a little bit lost with this. I tried to scape the $ with \ without luck.
sed -i '1s/.*/& $(echo "T$(echo "$j-3" | bc -l)_S$k")/' T_iSlicesExtraction_2.csv
is the best way to do what you want. For exampleawk -i inplace -v j="$j" -v k="$k" 'NR==1{$0="T" $0 (j-3) "_S" k} 1' T_iSlicesExtraction_2.csv
would be better than calling 3 separate commands to do such a simple thing. Chances are this line is part of a shell script that'd be much simpler, clearer, more robust, more efficient, and more portable if the whole thing was only written as a single awk script though. – Ed Morton Jun 01 '21 at 13:02