Take file as an input and run awk command on it

19 views Asked by At

I have a awk command which works fine when I run it directly on my terminal. However, now I want to take make a bash script that takes a file name as input and then runs the same awk command on it and saves the output. How can I achieve the? My awk command is:


awk -F, '/^#/ {next;} /^VariantID/ {printf("##fileformat=VCFv4.2\n");split($0,header);for(i=5;i<=NF;i++) printf("##INFO=<ID=%s,Number=1,Type=String,Description=\"%s\">\n",$i,$i);printf("#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n");next ;} {printf("%s\t%s\t%s\t%s\t%s\t.\t.\t",$2,$3,$1,$5,$6);for(i=5;i<=NF;i++) printf("%s=%s;",header[i],$i);printf("\n");}' > atlas.chr2.vcf

I want to put this is in a bash script which takes filename as input and then run awk command on it so something like:

#!/bin/bash

##Take filename as input


###Run awk command on it and the output in a file:
awk -F, '/^#/ {next;} /^VariantID/ {printf("##fileformat=VCFv4.2\n");split($0,header);for(i=5;i<=NF;i++) printf("##INFO=<ID=%s,Number=1,Type=String,Description=\"%s\">\n",$i,$i);printf("#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n");next ;} {printf("%s\t%s\t%s\t%s\t%s\t.\t.\t",$2,$3,$1,$5,$6);for(i=5;i<=NF;i++) printf("%s=%s;",header[i],$i);printf("\n");}' > atlas.chr2.vcf

Insights will be appreciated.

0

There are 0 answers