Membership questions? Log in issues? Email info@brewersassociation.org

Author Topic: awk sucks  (Read 2604 times)

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
awk sucks
« on: February 10, 2011, 01:21:31 am »
Why the hell would awk return a value of 1 when I say

awk '{ if ( $9 == "step" ){ print $9 }}' $mut1 > $out1

and the value in that column is 0?  Isn't this a string comparison?  Why does 0 == "step" ?  Makes no sense.  This fixed it though, after 20 minutes of trouble shooting.  Stupid awk.

awk '{ if ( $9 ~ /step/ ){ print $9 }}' $mut1 > $out1
Tom Schmidlin

Offline phillamb168

  • Brewmaster General
  • *******
  • Posts: 2351
  • Lardy, France
    • My Job
Re: awk sucks
« Reply #1 on: February 10, 2011, 02:07:27 am »
Easier if you just do everything in Assembly, you know.
I'm on twitter: phillamb168
----
morticaixavier for governing committee!

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
Re: awk sucks
« Reply #2 on: February 10, 2011, 02:10:32 am »
:o ;D
Easier for whom?
Tom Schmidlin

Offline phillamb168

  • Brewmaster General
  • *******
  • Posts: 2351
  • Lardy, France
    • My Job
Re: awk sucks
« Reply #3 on: February 10, 2011, 02:53:31 am »
Certainly not me, although I'm a PHP developer.
I'm on twitter: phillamb168
----
morticaixavier for governing committee!

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
Re: awk sucks
« Reply #4 on: February 10, 2011, 03:00:53 am »
Ugh, I'm off to bed.  This script is taking forever, and I'm tired/bored.  Thanks for replying phil. :)
Tom Schmidlin

Offline phillamb168

  • Brewmaster General
  • *******
  • Posts: 2351
  • Lardy, France
    • My Job
Re: awk sucks
« Reply #5 on: February 10, 2011, 04:03:12 am »
Hey, no problem. At least you don't have to write a how-to for a rather technically un-savvy client. Sigh.
I'm on twitter: phillamb168
----
morticaixavier for governing committee!

Offline oscarvan

  • Senior Brewmaster
  • ******
  • Posts: 1707
Re: awk sucks
« Reply #6 on: February 10, 2011, 06:01:53 am »
A few decades ago I was programming assembly on a DEC VAX11-750 and learning how to fly airplanes. The airplanes won. I do remember that syntax is everything..... (after flow charts of course....)
Wooden Shoe Brew Works (not a commercial operation) Bethlehem, PA
http://www.woodenshoemusic.com/WSBW/WSBW_All_grain_Setup.html
I brew WITH style..... not necessarily TO style.....

Offline phillamb168

  • Brewmaster General
  • *******
  • Posts: 2351
  • Lardy, France
    • My Job
Re: awk sucks
« Reply #7 on: February 10, 2011, 07:08:37 am »
Whatcha fly Oscarvan?

I was Civil Air Patrol when I was younger and am about 10 hours shy of my Single Engine rating. I'm sure that doesn't compare to what you're flying, but I was curious.

FWIW the local air club here has so great vintage WWII fighters and bombers - ME109s, P-51s, and a Zero. I haven't joined the club yet, so I dunno if they let you check 'em out, but I should probably go ask.
I'm on twitter: phillamb168
----
morticaixavier for governing committee!

Offline oscarvan

  • Senior Brewmaster
  • ******
  • Posts: 1707
Re: awk sucks
« Reply #8 on: February 10, 2011, 07:13:11 am »
Nothing exotic....people movers. Started on the 727 then DC-9, B737 200/300/500/700/800/900 Nowadays B757 200/300 and B767 200/400 Lost track of my hours a long time ago. It's a job. A good job, but it's a job.
Wooden Shoe Brew Works (not a commercial operation) Bethlehem, PA
http://www.woodenshoemusic.com/WSBW/WSBW_All_grain_Setup.html
I brew WITH style..... not necessarily TO style.....

Offline MrNate

  • Brewmaster
  • *****
  • Posts: 967
  • Bridgewater, NJ
Re: awk sucks
« Reply #9 on: February 10, 2011, 07:21:59 am »
Don't know PHP, but possibly data type error? If it can't evaluate $9 as equal to a given string because $9 isn't a string... Like I said, I don't know PHP at all.
“If one's actions are honest, one does not need the predated confidence of others, only their rational perception.”

Offline Tim McManus

  • Assistant Brewer
  • ***
  • Posts: 236
    • Haskell Brewing Company
Re: awk sucks
« Reply #10 on: February 10, 2011, 07:47:51 am »
Easier if you just do everything in Assembly, you know.

I miss 65C02 assembler.
Tim McManus
Haskell, NJ

narvin

  • Guest
Re: awk sucks
« Reply #11 on: February 10, 2011, 09:30:32 am »
Why the hell would awk return a value of 1 when I say

awk '{ if ( $9 == "step" ){ print $9 }}' $mut1 > $out1

and the value in that column is 0?  Isn't this a string comparison?  Why does 0 == "step" ?  Makes no sense.  This fixed it though, after 20 minutes of trouble shooting.  Stupid awk.

awk '{ if ( $9 ~ /step/ ){ print $9 }}' $mut1 > $out1


Dunno, your first example should work.

Note that your regular expression in the second example is searching for any string containing the substring "step".  If you want to match only the entire word, you need to use /^step$/
« Last Edit: February 10, 2011, 09:34:47 am by narvin »

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
Re: awk sucks
« Reply #12 on: February 10, 2011, 09:50:46 am »
Don't know PHP, but possibly data type error? If it can't evaluate $9 as equal to a given string because $9 isn't a string... Like I said, I don't know PHP at all.
Thanks Nate.  I don't know, but either way it is fixed.  Unfortunately since I went to bed and wasn't watching the computer rebooted in the middle of the script so it could update the virus protection . . . so now I'm re-running the script and it's moving even slower now than last night. :'(
Tom Schmidlin

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
Re: awk sucks
« Reply #13 on: February 10, 2011, 09:59:17 am »
Why the hell would awk return a value of 1 when I say

awk '{ if ( $9 == "step" ){ print $9 }}' $mut1 > $out1

and the value in that column is 0?  Isn't this a string comparison?  Why does 0 == "step" ?  Makes no sense.  This fixed it though, after 20 minutes of trouble shooting.  Stupid awk.

awk '{ if ( $9 ~ /step/ ){ print $9 }}' $mut1 > $out1


Dunno, your first example should work.

Note that your regular expression in the second example is searching for any string containing the substring "step".  If you want to match only the entire word, you need to use /^step$/
Yeah, that's fine though because the only line that contains anything that matches is the first line, which is the one I'm trying to pull out of the file with that part of awk - the bit I included was just my troubleshooting line, the actual line is below.  I suspect it has something to do with it running inside of a perl script so I can pipe in a list of directories to go through, but either way it is working as expected now.

awk '{ if ( $9 ~ /step/ || ( $8 > 2499999 && $8 < 27500001 )) {print $0}}' $mut1 > $out1
Tom Schmidlin