In the following bash loop, I want to redirect content into a variable filename.
for i in {1..22};do echo $i > $i_output.txt; done
Unfortunately the files are not created. What I originally want to do is to grep on chromosomes in a file and create a file per chromosome. But this is less testable:
for i in {1..22}; grep -E "[a-z]+[0-9]+\t$i\t" rawdata.txt > $i_chr.txt;done
How can we redirect output in a for loop to a variable filename?