1

I want to run this awk statement from inside a shell script:

awk -F, '$45==341 && $47==341 && ($13==3) && $15 <=600 && $48==5410 && $50=="pattern"' \
full_path/logfile.log | cut -d, -f15 | sort -unr |head -1

If I run it directly from command line, it works perfectly but from inside a shell script it fails.

I understand there's an issue with shell script command line parameters and awk references, like $45, $47 and so on...

I tryed to escape $ without success.

Srini V
  • 11,045
  • 14
  • 66
  • 89
Juan Pablo
  • 1,213
  • 10
  • 15
  • @Cyrus great Edition! Thanks. in fact i'm using the full path to file. I think the issue is not there. – Juan Pablo Mar 22 '16 at 01:51
  • 1
    It's working fine for me. Can you include the appropriate snippet from your shell script? – Paul Hicks Mar 22 '16 at 02:00
  • 1
    BTW Are your tags correct? Linux and Solaris? – Paul Hicks Mar 22 '16 at 02:03
  • 9
    In what way does it "fail"? – glenn jackman Mar 22 '16 at 02:07
  • 1
    ah, Linux and Solaris. The default `/bin/awk` in Solaris is really (really!) old and missing a lot of features. Either use `/bin/nawk` or `/usr/xpg4/bin/awk`. Good luck. – shellter Mar 22 '16 at 02:19
  • You understand wrong - there are no issues with shell script command line parameters and awk references, like $45, $47 and so on... – Ed Morton Mar 22 '16 at 04:21
  • I am a bit concerned by `$50=="pattern"`. If the "pattern" really is a pattern, you should probably be using "~" rather than "==". – Mark Setchell Mar 22 '16 at 12:39
  • @MarkSetchell is right and we should never use the word "pattern" anyway as it's so ambiguous. Use the words "string" or "regexp" or "condition" (`$N~/regexp/{}` or `$N=="string"{action>}` or `{}`. The guys who invented awk got it wrong in the documentation when they talked about "pattern"s instead of "condition"s and we're suffering the lingering effects of that with all this "pattern" nonsense. – Ed Morton Mar 22 '16 at 12:55

0 Answers0