You are running the command on the same file, quant.sf
each time. You need to use your $fn
variable instead:
#!/bin/bash
for fn in /home/usr/Downloads/salmon-1.2.1_linux_x86_64/quants/SRR/quant.sf{8068516..8068543};
do
samp=`basename ${fn}`
echo "Processing sample ${samp}"
awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "", $1); print }' "$fn" > equant.sf
done
However, that would also fail since it will be simply overwriting a file called equant.sf
in your current directory with the results of processing each file.
I can't be sure, since you haven't actually shown us your file structure, but I suspect what you're looking for is actually this:
#!/bin/bash
for fn in /home/usr/Downloads/salmon-1.2.1_linux_x86_64/quants/SRR/quant.sf{8068516..8068543};
do
samp=`basename ${fn}`
outName="${fn/quant.sf/equant.sf}"
echo "Processing sample ${samp}"
awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "", $1); print }' "$fn" > "$outName"
done
The outName="${fn/quant.sf/equant.sf}"
replaces the first occurrence of quant.sf
in the variable $fn
with equant.sf
, keeping the path and thereby ensuring that the output of each file is stored in the same directory with the name equant.sfNNNNNN
. For example:
$ fn=/home/usr/Downloads/salmon-1.2.1_linux_x86_64/quants/SRR/quant.sf8068516
$ echo ${fn/quant.sf/equant.sf}
/home/usr/Downloads/salmon-1.2.1_linux_x86_64/quants/SRR/equant.sf8068516
This means that your awk command will become:
awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "", $1); print }' /home/usr/Downloads/salmon-1.2.1_linux_x86_64/quants/SRR/quant.sf8068516 > /home/usr/Downloads/salmon-1.2.1_linux_x86_64/quants/SRR/equant.sf8068516