LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-07-2009, 11:13 PM   #1
first_linux
LQ Newbie
 
Registered: May 2007
Posts: 5

Rep: Reputation: 0
Does awk depend on the environment variables ?


I have a simple awk command which works fine for me but does not work for a colleague. The only difference I can see is that I have CShell while he has Bash, though on changing my shell to Bash, I get it to work there as well. What are some of the possible reasons that this may not be working for him ?

Command is
echo "ios_1.2-io" | awk '/^[a-zA-Z0-9._-]*$/ {print 1}'

For my colleague, the error is
awk: cmd. line:1: fatal: Invalid range end: /^[a-zA-Z0-9._-\(\)]*$/

Thanks for your pointers.
 
Old 05-08-2009, 12:09 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Possibly different versions of awk: there's awk, nawk, gawk. One may be symlinked to another. Also check the contents of $PATH.
 
Old 05-08-2009, 03:19 AM   #3
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 669

Rep: Reputation: 134Reputation: 134
Quote:
Originally Posted by first_linux View Post
I have a simple awk command which works fine for me but does not work for a colleague. The only difference I can see is that I have CShell while he has Bash, though on changing my shell to Bash, I get it to work there as well. What are some of the possible reasons that this may not be working for him ?

Command is
echo "ios_1.2-io" | awk '/^[a-zA-Z0-9._-]*$/ {print 1}'

For my colleague, the error is
awk: cmd. line:1: fatal: Invalid range end: /^[a-zA-Z0-9._-\(\)]*$/

Thanks for your pointers.
Ranges such as a-z may depend on language. Do you and your colleague have some LANG environment variable ?
 
Old 05-08-2009, 03:48 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

I've seen this behavior before (awk on a SUN box). It is not related to the shell (csh/bash/etc), but as already stated by chrism01, a difference in awk.

I do believe you can solve the problem by changing the location of the last dash (it did work for me):

[a-zA-Z0-9._-] becomes [-a-zA-Z0-9._]

Some awk version expect a range if you use with this: _- and report a range error if there is no valid end.
The following example also confuses some awk versions: [a-Z] instead of [a-zA-Z].

Hope this helps.
 
Old 05-08-2009, 03:51 AM   #5
first_linux
LQ Newbie
 
Registered: May 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Hi chrism01 - that is interesting because if I ran the command with gawk I get the same error. I need to go back and check which awk is my colleague using because of his PATH

Hi Valery - yes, in my env, LANG=en_US and my colleague has LANG=en_US.UTF-8. Does this make a difference ?

Thanks,
 
Old 05-08-2009, 04:00 AM   #6
first_linux
LQ Newbie
 
Registered: May 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Hi Druuna, Yes, your solution works for me whether I use gawk or awk and so I think it will work for my colleague as well. Will get him to try it out tomorrow.
Thanks, you and Chris have helped me understand the problem.
 
Old 05-08-2009, 04:17 AM   #7
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 669

Rep: Reputation: 134Reputation: 134
Quote:
Originally Posted by first_linux View Post
Hi chrism01 - that is interesting because if I ran the command with gawk I get the same error. I need to go back and check which awk is my colleague using because of his PATH

Hi Valery - yes, in my env, LANG=en_US and my colleague has LANG=en_US.UTF-8. Does this make a difference ?

Thanks,
Just try - run his awk with yours LANG and yours awk with his LANG
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning variables by awk(?) bioinformatics_guy Linux - Newbie 2 02-19-2009 01:01 PM
problems with variables using sed or awk in script FeatherKing Programming 4 09-15-2008 12:13 AM
How to make 2 variables from one variable value in awk intikhabalam Linux - General 1 07-30-2008 05:32 AM
Can you use grep / awk on variables instead of files? zest n zeal Linux - Newbie 2 02-11-2008 01:37 PM
awk: /matching/ variables passed with -v aunquarra Linux - General 2 02-17-2005 07:47 PM


All times are GMT -5. The time now is 01:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration