The UNIX and Linux Forums  

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
Pass csh variable to Perl Raynon Shell Programming and Scripting 9 10-19-2007 10:46 PM
How to pass a variable to Awk ? Raynon Shell Programming and Scripting 24 02-26-2007 09:25 AM
getting the file name and pass as variable u263066 Shell Programming and Scripting 1 09-12-2006 05:38 AM
pass variable to awk inquirer UNIX for Dummies Questions & Answers 4 02-11-2004 03:23 AM
Pass variable to sed? kristy Shell Programming and Scripting 2 04-04-2002 04:14 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 04-03-2007
eja eja is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
How do I pass a variable to awk?

I have an awk statement where I Need to pass an environment variable but I cannot get it to work:

My evironment varible examples below:
$FILE1=/dev/fs/file.new
$FILE2=/dev/fs/file.old

Code below:

awk -F"|" '
BEGIN {
while( getline < "$FILE1" )
{ arr[$1]=1 }
}
arr[($1)] != 1 { print }
' $FILE2


I cannot hard code the file names into the awk statement. I need to apss the file name as a varibale. but my above awk is not reading $FILE1 as the value it is defined as in the environment.
  #2 (permalink)  
Old 04-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
$FILE1=/dev/fs/file.new
$FILE2=/dev/fs/file.old

nawk -F'|' -v OFS='|' '
   NR==FNR { arr[$1]; next }
   arr[$1]
' $FILE1 $FILE2

  #3 (permalink)  
Old 04-03-2007
eja eja is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
THank you for the reply.

Unfortunately I am running ina UNIX emulator WIndows Services for Unix. It does not ahve nawk. can this be done in awk?
  #4 (permalink)  
Old 04-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by eja
THank you for the reply.

Unfortunately I am running ina UNIX emulator WIndows Services for Unix. It does not ahve nawk. can this be done in awk?
worth tryin', ain't it?
  #5 (permalink)  
Old 04-03-2007
eja eja is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
I did after I sent the reply. Sorry should have thought before I typed.
  #6 (permalink)  
Old 04-03-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by eja
I did after I sent the reply. Sorry should have thought before I typed.
and....? the verdict is....???
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 06:18 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