lundi 27 septembre 2021

awk to print the colums with condition on header

I have this kind of input:

Vel RMSE H D20120122 D20130404 X Y 0.5 0.1 3 4 5 2 2

I would like to print only the colums containing the string D2, in order to have as output the following:

D20120122 D20130404 4 5

I tried like this: awk '{for(i=1;i<=NF;i++) if($i ~ /D2/) printf $i}' myfile

but it returns only the first row, i.e.:

D20120122 D20130404

Any idea?

Thanks

Aucun commentaire:

Enregistrer un commentaire