I am trying to use bash
to loop through a directory /path/to/data
using a prefix match from /path/to/file
. That match is obtained and works using the code below (in green)... what I can not seem to do is populate or update the corresponding prefix_file.txt
in /path/to/data
with the values in each of the data file in /path/to/data
. The data file are always named the same way and have a single value in them.
I don't know if the portion in blue is helpful, but my thinking was on a prefix match each ${f}_file.txt
is updated using the data file. Thank you :).
/path/to/data
ID-5_xx.number.txt ID-5_xx.diff.txt
67722024 180
ID-5_xx.test.txt ID-5_xx.common.txt
59733 92.249581%
AA-1_yy.number.txt AA-1_yy.diff.txt
46722024 138
AA-1_yy.test.txt AA-1_yy.common.txt
50033 82.248581%
current /path/to/file
ID-5_xx_file.txt
number=
test=
diff=
common=
AA-1_yy_file.txt
number=
test=
diff=
common=
desired /path/to/file
ID-5_xx_file.txt
number=67722024
test=59733
diff=180
common=92.249581%
AA-1_yy_file.txt
number=46722024
test=50033
diff=138
common=82.248581%
bash
for f in /path/to/data ; do # strat process loop for each sample
file=$(printf '%s' ${f}.*.txt)
fname=`basename $file` # strip of path
prefix=$(echo $fname | cut -d. -f1) # remove after .
if [[ $f = $prefix ]] # only execute file prefix match
cd /path/to/file # change directory to where ${f}_file.txt is
then [[ ${f}_file.txt == # update each ${f}_file.txt with values from /path/to/data
number=${sample}.number.txt
test=$qc_dir/extract/${sample}.test.txt
diff=$qc_dir/extract/${sample}.diff.txt
common=${sample}.common.txt ]]
fi
done