Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with awk PLS! 2

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file which contains multiple rows and 6 fields. It looks like this:

15RBLT 0 98 11 29 11
16RBLT 0 13 11 46 11

I need awk to search file beaster1_a which is this file, and print only the lines where fields 2,3, and 5 are greater than or equal to 6. I would need the whole line though. Then redirect to > beaster1_b. I know this is probably pretty easy, but I have been thrown into this and am going crazy! Please help if you can.
 
Hi beaster,

This may do it for you:

awk '{

if ((( $2 >= 6 ) && ( $3 >= 6 ) && ( $5 >= 6 ))) {
print

} else {

next
}

}' beaster1_a > beaster1_b

HTH


flogrr
flogr@yahoo.com

 
Great flogrr,
Looks like that is what I was looking for! For those that match the criteria of being >=6 will it still print the entire line or just the fields I was looking for? Because I still want $1 to print. I guess I will also have to paste in the upper words as well?

Thanks,
Beaster

I will test it out now...(y)
 
I tried the above response and I end up with a zero file. The original file has criteria in it that would produce an output, but I get nothing. I inserted it into to my script exactly the way it is above. Any thoughts?
Beaster
 
Field 2 in your example data is 0 which is not >= 6 so you should get an empty file.

CaKiwi
 
Your right, so if I want it to print the line if any of the fields meet the criteria, what would need to be changed? Good catch, I have been staring at it for hours...

Beaster
 
Change the if to:

if ((( $2 >= 6 ) || ( $3 >= 6 ) || ( $5 >= 6 ))){

CaKiwi
 
That was it! You both are awesome! Thanks again, this one works great now, I will try and work on the other one in the am.

Regards,
Beaster
 
Sorry-

I missed your point because "2,3, and 5" means AND
to me and not OR. However, what counts is your
problem got solved.



flogrr
flogr@yahoo.com

 
If I want to right justify each field, is it something I need to change the whole thing or just add something? to the printf statement?

I have almost completly finished the script after two weeks, this is the last portion!

You have all been a great help!
 
Beaster,

This program did not use a printf. Did you mean to add to your other thread which does have a printf?

CaKiwi

After all is said and done, a lot more will have been said than done.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top