Is there a way to run a awk script within bash script?
I have a large file (~40GB) that I want to split based on 3rd field. The third field can be either chr1, chr2 ... chr22, chrX and chrY (total 24 types). When I run
awk 'BEGIN{OFS=FS="\t"}$3=="chr1"{print $0}' inputfile.txt > inputfile_chr1.txt
It runs fine but when I try to loop it doesn't:
for i in {1..22} X Y; do
awk 'BEGIN{OFS=FS="\t"}$3=="chr${i}"{print $0}' inputfile.txt > inputfile_chr${i}.txt
done
I tried using single quotes for $3 and back slash to escape $3 but everything failed. Is there a better way to do this?