I have to cycle over the files present in a folder but I dont want to cycle over files with a specific pattern ("Reverse"). Here is the code
Thanks
DIRECTORY=/Users/Qi.Wang/projects/CH12F3/data/CH12F3.LAM-HTGTS_mMYC.220512
outputDir=/Users/Qi.Wang/projects/CH12F3/
pw=$(pwd)
cat blank.txt > ./config.txt
c="$pw/config.txt"
o=0
for i in $DIRECTORY/*.fna; do
((o=o 1))
s=${i##*/}
b=${s%.fna}
b="${o}_$(echo $b | awk '{ gsub(/_PairEnd /, " " ); print $1 }')"
outputDirs="$outputDir$b"
printf "%s\t" $b >> ./config.txt
printf "%s\t" $s >> ./config.txt
cat end.txt >> ./config.txt
printf "perl /Users/andy/projects/HTGTS/pipeline/align_tools/TLPpipeline.pl %s %s which=%s assembly=mm9 blatopt=mask=lower outdir=/%s -skipred -skipredadd -skipblu -skipbluadd \n" $c $DIRECTORY $o $outputDirs >> ./command.sh
done
I Also have another minor problem. When i printf outdirs=%s the variable that is printed is $outputDir that starts with a "/" but after it got printed by printf, looks like the / is not there anymore.
CodePudding user response:
Your awk
command puts spaces $b
, so $outputDirs
will contain spaces. Therefore, you need to quote it to make it a single argument to printf
. You should also quote all the other variable arguments.
Also, since you're creating a perl
command line, you'll want outdir=%s
to be a single argument, so you should put single quotes around that as well.
printf "perl /Users/andy/projects/HTGTS/pipeline/align_tools/TLPpipeline.pl '%s' '%s' 'which=%s' assembly=mm9 blatopt=mask=lower 'outdir=/%s' -skipred -skipredadd -skipblu -skipbluadd \n" "$c" "$DIRECTORY" "$o" "$outputDirs" >> ./command.sh
To skip files with Reverse
in the name, enable extended globbing and use a non-matching pattern.
shopt -s extglob
for i in "$DIRECTORY"/!(*Reverse*).fna; do