1

I have this bash loop below which uses perl script. It is expected to output something for every $i in every $f which I want to save as separate text file. The code I have below does the job, but instead of saving for individual $i, it saves for $f and puts the output of 18 to 24 in one file. May be I have to reposition the write command in this loop or is there a better way to do this?

for f in *.fastq; do 
echo "Processing: " $f
for i in $(seq 18 24); do
echo "Doing: " $i
perl /home/owner/perl/count.pl $f $i
done > >(tee /media/owner/${f}_${i}.txt) 2>&1
done
3
  • Loop redirections apply to the entire loop, not each iteration. Commented Jul 28, 2018 at 0:05
  • Ok. so is there a way to write for $i output? Thanks Commented Jul 28, 2018 at 0:06
  • 1
    Use the redirection on the perl command instead. Or create a { group; } and redirect that Commented Jul 28, 2018 at 0:07

1 Answer 1

1

Redirections on loops are per loop, not per iterations.

You can instead use a { command group; } around the commands you want and redirect that:

for f in *.fastq;
do 
  echo "Processing: " $f
  for i in $(seq 18 24);
  do
    {
      echo "Doing: " $i
      perl /home/owner/perl/count.pl $f $i
    } > >(tee /media/owner/${f}_${i}.txt) 2>&1
  done
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.