AWK greater than?

Sorry for such a basic question, but I have spent hours trying to work this out! I need an awk command (or similar) that will look at a text file and output to the screen if the 4th column of each line has a value greater than or equal to x.

data.txt
This is the 1 line
This is the 2 line
This is the 3 line

So if x was 2 I would expect it to output

This is the 2 line
This is the 3 line

I've found a number of awk command on the net that let you output if the string length is a certain size, but I can't find anything on how to check if a field has a certain value. Does such a command exist? (I'm using Solaris by the way)

Thanks for any help.

Try this probably complicated but works

for i in `cat data.txt | awk '{print $4}'`
> do
> if [ $i -ge 2 ]
> then
> cat data.txt | grep "$i"
> fi
> done

U will get Output:

This is the 2 line
This is the 3 line

Thanks for that it works a treat - typical of Unix to need such a long winded script for such a simple task! :wink:

Edit:- Just found an easier way of doing it. Weird that I searched this forum and didn't find a way, but once I have posted the question it appears in the "Similar Threads" bit down the bottom.

Anyhoo, this works a treat too (and is a lot shorter so I'll apologise to Unix for calling it long winded!): awk ' $4 > 2 ' data.txt

awk ' $4 >= 2 ' data.txt

Not at all true if you know what you are doing in UNIX.

Here is a one liner which does what you want.

awk -v x=2 '$4 >= x'  data.txt

Just set x to any value you want via the "-v x=" option.

It's OK, I've already apologised further up the thread for saying it was long winded. :b:

Thanks for all the help guys.

More SImpler one!!!!!!!!!!!!!!!!!!!!!!

awk '$4>=2{print}' filename

Regards,
aajan