awk - how to print specific field if a string is matched

hi gurus,

I would like to be able to use awk to process 1 file as such:

abc 1 2 3 4 5 6 7 8 9 10
flags 1 2 4 
flags 1 2 5
abc 2 3 4 5 6 7 8 9 10 11
flags 1 2 3
abc 4 5 6 7 8 9 6 7 78 89 
flags 1 2 3 
flags 1 2 4
flags 1 2 3 4

I would like to be able to print field 1 and 5 when the line starts with abc and also print field 2 3 on the lines that start with flags
Any tips?

Thanks

awk '{if($0~/^abc/){print $1,$2,$3,$4,$5}else if($0~/^flags/){print $2,$3}}' FileName.txt 

Perfect, thank you so much....

Try also

awk   '/^abc/      {print $1,$5}
       /^flags/    {print $2,$3}
      ' file

Thanks Rudi, that works great too :slight_smile: