The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 11:36 PM
a weird issue with "while" block sleepy_11 Shell Programming and Scripting 7 08-06-2007 11:33 PM
weird domain issue. thirddegreekris UNIX for Advanced & Expert Users 2 05-04-2007 12:42 AM
HP-UX weird FTP ? IngmarMeins HP-UX 10 11-29-2005 08:22 PM
Weird SSH issue AKM UNIX for Advanced & Expert Users 6 11-08-2004 02:13 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-11-2008
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
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
  #2 (permalink)  
Old 04-11-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

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

Join Date: Aug 2005
Posts: 68
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.
  #4 (permalink)  
Old 04-11-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

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

Code:
{print red}
instead of:

Code:
{print $red}
Regards
  #5 (permalink)  
Old 04-11-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

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

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

nawk: can't open file {print red}
source line number 1
  #7 (permalink)  
Old 04-11-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

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

Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0