How to search a number in a certain field

Hello,

I have a file that looks like this:

 
num11 num12 num13 word1
num21 num22 num23 word2
num31 num32 num33 word3
.
.
.

I would like to search for the lines that contain a given number, but I need to narrow the search only to the first field, that means that the number has to be here:

 
num11
num21
num31
.
.
.

can I do it with grep? Or is there another possibility?

Thank you,
Shira.

nawk '{print $1}' <file> | grep -n <num>

Hi, thanks!
Is there a version withour nawk?

Use awk

For first field:

grep '^num1' infile

For third field:

grep '^[^ ]* [^ ]* num3' infile

Or better, use awk:

awk '{ if($3 == num3 ) print }' infile