I am trying to cut a range of fields in awk . The below seems to work for removing field 50, but what is the correct syntax for removing a range ( $50-$62 ). Thank you :).
The code that you posted originally and the code suggested by RudiC will remove any empty fields from your input file in addition to the fields you want to remove. The following will only remove fields 50 through 62, inclusive:
awk '
BEGIN { FS = OFS = "\t"
}
{ for(i = 1; i <= NF; i++)
if(i < 50 || i > 62)
printf("%s%s", $i, (i == NF) ? ORF : OFS)
}' test.vcf.hg19_multianno.txt > output.csv
The above code should do what you want (assuming that you have at least 63 fields in each input line). If some lines have less than 63 input fields, slightly different logic would be needed to ensure that each line is properly terminated and that no unneeded field separators are included in the output (after we get a clear description of whether empty fields should be added to the ends of short field count lines or if they should be omitted).
As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .