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 Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
manipulate a passed in parameter rudoraj Shell Programming and Scripting 2 06-11-2007 02:04 PM
Perl script variable passed to Oracle query rahulrathod Shell Programming and Scripting 1 05-30-2007 09:57 AM
Assigning a Variable all the Parameters passed samit_9999 UNIX for Dummies Questions & Answers 2 12-04-2006 05:21 PM
variable passed to awk whatisthis UNIX for Dummies Questions & Answers 8 09-15-2004 01:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2004
whatisthis's Avatar
whatisthis whatisthis is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 175
Question variable passed to awk

Does anybody know how to print a variable passed to awk command?

awk -F"|" 'BEGIN {print $job,"\n","Question \n"} {print $1,$2$4," ",$3}' "job=$job1" file1


I am trying to pass job the variable job1.

the output is blank.

??
  #2 (permalink)  
Old 09-14-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Use the -v switch to pass in a variable to Awk. Go to ]GNU and search for gAwk documentation for more details.

Code:
awk -v job=$job BEGIN '{FS= "|"; print "$job\n","Question \n"} {print $1,$2,$4," ",$3}'  file1

Last edited by google; 09-14-2004 at 10:07 PM..
  #3 (permalink)  
Old 09-15-2004
whatisthis's Avatar
whatisthis whatisthis is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 175
It's still not working.
variable $job is not empty string. but when it printed, it always prints JOB $job


echo job is $job
nawk -F"|" -v JOB=$job 'BEGIN {print "JOB ","$job\n"}
{print $1,$2," ",$4,"\n"}' list
  #4 (permalink)  
Old 09-15-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Thats because you are using "print" and placing job in quotes. Try using printf instead and using the %s notation.
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 05:31 AM.


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