# awk shell script

I have a folder named quant. Inside this folder I have 27 folders named SRR8068516_quant to SRR8068543_quant. I want to edit a file inside these folders titled quant.sf and produce an output. I attempted writing a shell script to do so:

    #!/bin/bash
do
samp=basename ${fn} echo "Processing sample $${samp}" awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "",$$1); print }' quant.sf > equant.sf done  When I run the script it gives me an error saying : Processing sample quant.sf8068516 awk: cannot open quant.sf (No such file or directory). What is wrong that I am doing. Kindly help. ## 1 Answer You are running the command on the same file, quant.sf each time. You need to use your $fn variable instead:

#!/bin/bash
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
samp=basename ${fn} outName="${fn/quant.sf/equant.sf}"
echo "Processing sample ${samp}" awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "",$1); print }' "$fn" > "$outName"

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