Author Topic: awk sucks  (Read 1616 times)

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
    • View Profile
awk sucks
« on: February 10, 2011, 08: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
    • View Profile
    • My Job
Re: awk sucks
« Reply #1 on: February 10, 2011, 09: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
    • View Profile
Re: awk sucks
« Reply #2 on: February 10, 2011, 09:10:32 AM »
:o ;D
Easier for whom?
Tom Schmidlin

Offline phillamb168

  • Brewmaster General
  • *******
  • Posts: 2351
  • Lardy, France
    • View Profile
    • My Job
Re: awk sucks
« Reply #3 on: February 10, 2011, 09: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
    • View Profile
Re: awk sucks
« Reply #4 on: February 10, 2011, 10: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
    • View Profile
    • My Job
Re: awk sucks
« Reply #5 on: February 10, 2011, 11: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
    • View Profile
Re: awk sucks
« Reply #6 on: February 10, 2011, 01:01:53 PM »
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
    • View Profile
    • My Job
Re: awk sucks
« Reply #7 on: February 10, 2011, 02:08:37 PM »
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
    • View Profile
Re: awk sucks
« Reply #8 on: February 10, 2011, 02:13:11 PM »
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
    • View Profile
Re: awk sucks
« Reply #9 on: February 10, 2011, 02:21:59 PM »
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
    • View Profile
    • Haskell Brewing Company
Re: awk sucks
« Reply #10 on: February 10, 2011, 02:47:51 PM »
Easier if you just do everything in Assembly, you know.

I miss 65C02 assembler.
Tim McManus
Haskell, NJ

Offline narvin

  • Brewmaster General
  • *******
  • Posts: 2269
  • Baltimore
    • View Profile
Re: awk sucks
« Reply #11 on: February 10, 2011, 04:30:32 PM »
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, 04:34:47 PM by narvin »
Please do not reply if your[sic] an evil alien!
Thanks

Offline tschmidlin

  • I must live here
  • **********
  • Posts: 8198
  • Redmond, WA
    • View Profile
Re: awk sucks
« Reply #12 on: February 10, 2011, 04:50:46 PM »
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
    • View Profile
Re: awk sucks
« Reply #13 on: February 10, 2011, 04:59:17 PM »
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