The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Weird Issue with crontab. Cameron HP-UX 3 04-21-2008 08:36 PM
a weird issue with "while" block sleepy_11 Shell Programming and Scripting 7 08-06-2007 08:33 PM
weird domain issue. thirddegreekris UNIX for Advanced & Expert Users 2 05-03-2007 09:42 PM
HP-UX weird FTP ? IngmarMeins HP-UX 10 11-29-2005 04:22 PM
Weird SSH issue AKM UNIX for Advanced & Expert Users 6 11-08-2004 10:13 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2008
Registered User
 

Join Date: Aug 2005
Posts: 64
Weird Awk issue

Hi All,
a bit of a weird one here. I'm trying to pass a variable into an awk command, and I keep getting an error.

I have the line

nawk -F"," -v red=$random_variable '{print $red}' $w_dir/$file_name > $w_dir/${column_name}

that keeps failing with the error

nawk: can't open file {print $red}
source line number 1


It's a bit weird, because I actually have another similar line later in my script that works perfectly

abbreviation=$(head -$counter $w_dir/$file_name| tail -1|nawk -F"," -v rad=$index '{print $rad}')

Maybe that's because the output is being assigned to another variable?
Any assistance will be very much appreciated.

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-11-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,502
are there shell metacharacters in $random_variable that cause the shell to interpret things differently?
Reply With Quote
  #3 (permalink)  
Old 04-11-2008
Registered User
 

Join Date: Aug 2005
Posts: 64
When I echo $random_variable, which have done while trying to troubleshoot, I get a number - 10, 11 or 13.

I have even tried running substituting the value

nawk -F"," -v red=13 '{print $red}' $w_dir/$file_name > $w_dir/${column_name}


Still the same error.
Reply With Quote
  #4 (permalink)  
Old 04-11-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,667
Don't preface the variabele with a '$' sign:

Code:
{print red}
instead of:

Code:
{print $red}
Regards
Reply With Quote
  #5 (permalink)  
Old 04-11-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,111
$red is perfectly valid if it means, say, field no. 13. In any event the error message is, indeed, weird.
Reply With Quote
  #6 (permalink)  
Old 04-11-2008
Registered User
 

Join Date: Aug 2005
Posts: 64
I tried again.

nawk: can't open file {print red}
source line number 1
Reply With Quote
  #7 (permalink)  
Old 04-11-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,667
Echo the used variables to see if they setted proper.

Regards
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0