Print columns that start with a specific string
With awk
:
awk '{for(i=5;i<=NF;i++){if($i~/^ANC=/){a=$i}} print $1,$2,$3,$4,a}' file
for(...)
loops through all fields, starting with field 5 (i=5
).if($i~/^ANC=/)
checks if the field starts withANC=
a=$i
if yes, set variable a to that value
print $1,$2,$3,$4,a
print fields 1-4 followed by whatever is stored ina
.
Can be combined with BEGIN {OFS="\t"}
of course.