When I run the below bash
I get the expected output, which is the sum of all matching targets less than 20 in $file1
. The filename in the directory is fixed (in bold).
for file1 in /home/cmccabe/Desktop/test/panel/reads/16-0000_EPIL70.txt ; do
bname=`basename $file1`
pref=${bname%%_*.txt}
awk '{gsub(/[()]/,_)} \
count[$5]==""{ count[$5]=0 }
$7 < 20{ count[$5]++}
END{
for(k in count)
printf "%s %d\n", k, count[k]
}' $file1 > /home/cmccabe/Desktop/test/panel/20x/base/16-0000_allepil70.bed
done
The desired bash
is the exact same except the unique numerical digits, 16-0000
are read into a variable {pref}
. This is because there can be multiple files with the same extension, but the digits are always unique.
for file1 in /home/cmccabe/Desktop/test/panel/reads/${pref}_EPIL70.txt ; do
bname=`basename $file1`
pref=${bname%%_*.txt}
awk '{gsub(/[()]/,_)} \
count[$5]==""{ count[$5]=0 }
$7 < 20{ count[$5]++}
END{
for(k in count)
printf "%s %d\n", k, count[k]
}' $file1 > /home/cmccabe/Desktop/test/panel/20x/base/${pref}_allepil70.bed
done
awk: fatal: cannot open file `/home/cmccabe/Desktop/test/panel/reads/16-0000_epil70lessthan20xregions.txt_EPIL70.txt' for reading
The file that it is looking for is not in that directory, but not sure why it is even looking for it as I do not reference it at all in the command or do I? Thank you :).
ls -l /home/cmccabe/Desktop/test/panel/reads
total 10952
-rw-rw-r-- 1 cmccabe cmccabe 11214550 Feb 7 07:27 16-0000_EPIL70.txt