Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Variable 2

Status
Not open for further replies.

nithink

Programmer
Nov 7, 2002
92
US
hi, I've a c-shell script, in which i've a variable "ydate" which has a value 20021106. And I want to use this variable in a awk statement as below,
awk -F_ '{if ($1 ~ /xyz/ && $2 > $ydate) print $0}' ./tmp1 > ./tmp2

but it doesnt take the value of "ydate".. it works well when i hardcode that value without using the variable... can you pls help me get out of this...
 
awk -F_ -v ydate=$ydate '{if ($1 ~ /xyz/ && $2 > ydate) print $0}' ./tmp1 > ./tmp2 vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
hi vgersh, thanx for your reply but its giving this following error when run... can you pls let me know whats this error abt ?

awk: syntax error near line 1
awk: bailing out near line 1
awk: syntax error near line 1
awk: bailing out near line 1
 
if on Solaris, use 'nawk' vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
THank yu very much Vgersh.. it worked perfectly fine.. If possible can i know what that syntax actually does ? 'coz i'm totally new to scripting..

nawk -F_ -v ydate=$ydate '{if ($1 ~ /xyz/ && $2 > ydate) print $0}' ./tmp1 > ./tmp2

 
on solaris
cd /bin
mv awk old.awk
ln -s nawk awk
-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 

-v ydate=$ydate - takes the value of SHELL's variable 'ydate' and assigns it to the NAWK's variable 'ydate' [bad naming.... I know, I know]

The NAWK's 'ydate' is passed to the NAWK script and used for comparison.

You don't want me to explain the REST of the script, do you? ;)

vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
thanks Vgersh... got it...

thanks jamisar...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top