First of all: I hope the question is comprehensible, otherwise please let me know and I will do my best to make it more clear.
This is a follow up to Replace one entire column in one file with a single value from another file combined with R Pass Variable from R to Unix
Here goes:
I am running several scripts (Perl, python and R) in one Unix script and need to pass outputs of these scripts to Unix and combine information from different files these scripts create.
I have a working code which is a combination of the above mentioned questions:
The output from the R script called getenergie.R
is a filename. There are several such filenames which are returned and I need to write into each of these files and replace column 11 of these files with a value which comes from another file (COP1A_report1
) and is called value.
RES=($(./../getenergies.R))
for pdbnames in "${RES[@]}"
do
#write the one value from COP1A_report1 into column 11 of a file and save as TESTING
value=$(awk -F, 'NR==1{print $2;exit}' ./../COP1A_report1)
awk '{$11 = v} 1' v="$value" ${pdbnames} > TESTING
printf "$value ${pdbnames}\n"
done
What I need is a way to loop over this so that it writes one value from COP1A_report1
(row $2, line 1) into column 11 of a file called like the first filename stored in $pdbnames
, save it as a unique file and go to COP1A_report1
(row $2, line 2), write that into column 11 of a file called like the second filename stored in $pdbnames
and so on...
What is the smartest way of doing that? I can imagine sth
like the code below, but sth
is wrong with the syntax and I do not get any errors, just an empty value variable.
Any ideas?
counter=1
RES=($(./../getenergies.R))
for pdbnames in "${RES[@]}"
do
value=$(awk -F, 'NR==$counter{print $2;exit}' ./../COP1A_report1) #NR=1 needs to be changed to go through the entire list...
awk '{$11 = v} 1' v="$value" ${pdbnames} > TESTING$counter
counter=$(echo $counter+1 |bc)
printf "$value ${pdbnames}\n"
done