![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pass csh variable to Perl | Raynon | Shell Programming and Scripting | 9 | 10-19-2007 06:46 PM |
| How to pass a variable to Awk ? | Raynon | Shell Programming and Scripting | 24 | 02-26-2007 06:25 AM |
| getting the file name and pass as variable | u263066 | Shell Programming and Scripting | 1 | 09-12-2006 01:38 AM |
| pass variable to awk | inquirer | UNIX for Dummies Questions & Answers | 4 | 02-11-2004 12:23 AM |
| Pass variable to sed? | kristy | Shell Programming and Scripting | 2 | 04-04-2002 12:14 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
I did after I sent the reply. Sorry should have thought before I typed.
|
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
|||
|
|||
|
Yes that would help. you can tell I am a newbie. Works great. I changed it slightly but it works.
awk -F'|' ' NR==FNR { arr[$1]=1; next } arr[$1] !=1' $HOME/$WORK/$NewFile $HOME/$COMPARE/$OldFile > $HOME/$WORK/$NewFile.del The above compares yesterdays file to todays and find deleted records. Thanks very much for the help. |
|||
| Google The UNIX and Linux Forums |