nawk and variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nawk and variables
# 1  
Old 07-11-2005
nawk and variables

Hi guy's

Im trying to pass variables into nawk and then match them on a value within a record but it don't seem to be working. If i put in the dates i want to see then it works fine..

#!/usr/bin/ksh -x
YEST=$(/usr/local/bin/perl -e '@T=localtime(time-86400);printf("%02d/%02d/%02d\n",$T[4]+1,$T[3],($T[5]+1900)%100)')
DATE=$(date +%m/%d/%y)
MON=$(date +%m)
DAY=$(date +%d)
YEAR=$(date +%y)

bpdbjobs -report | /usr/bin/nawk -v DATE=$DATE -v YEST=$YEST '
{
if ( NF == 13 )
if ( $12 ~ /07\/09\/05/ || $12 ~ /07\/10\/05/ || $12 ~ /07\/11\/05/)
if ( $3 ~ /Done/ && $4 > 0 )
print

elseif ( NF == 12 )
if ( $11 ~ /07\/09\/05/ || $11 ~ /07\/10\/05/ || $11 ~ /07\/11\/05/)
if ( $3 ~ /Done/ && $4 > 0 )

print

}'

I want to have the following line looking like this and using the variable, if that makes sense


if ( $12 == YEST || $12 == DATE )

print


although this doesn't work how i would like i have even tried splitting up the %d / %m / %y but still no joy. Is some control symbol used to tell awk it is a variable with a value ?

Thanks in advance...

Kenny

Last edited by plimpix; 07-11-2005 at 12:33 PM..
# 2  
Old 07-11-2005
are you passing 'TODAY' and 'YEST ' to awk?
or are you still passing 'DATE'?
# 3  
Old 07-11-2005
Yea just updated my post didn't quite read correct. Yea passing the variables to nawk with -v

kenny
# 4  
Old 07-11-2005
can you print the values of 'TODAY' and 'YEST' in the 'BEGIN' block of nawk to make sure you're passing what you think you're passing? [with no leading/trailing extra chars]
# 5  
Old 07-11-2005
I know the variables are getting there for i tried that but seems that either awk doesn't like what im trying to do with the variable for if i use

if ( $12 ~ /DATE/ )

then it thinks im matching on word DATE when i don't want this.. but im wondering if the issue is with the / for i have not exited the / with \/

For i printed date before it done the matching and show up fine..
# 6  
Old 07-11-2005
if ( $12 ~ DATE )
# 7  
Old 07-11-2005
looks like the or operator is causing issues then for if i have the following

if ($12 ~ DATE )

it works

But not if i have

if ($12 ~ DATE || $12 ~ YEST)

it don't work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple bash variables passed into nawk

I have a file that has 2 fields called b_file: 11977 DAR.V3.20150209.1.CSV 3295 DAR.V3.20150209.1.CSV 1721 DAR.V2.20150210.1.CSV I need to search a sftplog using the field 1, but want to maintain the relationship between field 1 and 2. I am passing field 1 as a parameter in a bash loop. ... (14 Replies)
Discussion started by: smenago
14 Replies

2. Shell Programming and Scripting

Two shell variables using nawk

How do you use two shell variables in awk? I am using Solaris 10 and don't have GNU products installed. File (transportation.txt) contents: car make boat model airplane landing snowmobile track bicycle helmet sled housing Thanks to this forum this code works (prints everything from the... (4 Replies)
Discussion started by: thibodc
4 Replies

3. Shell Programming and Scripting

nawk variables

Hi - The following nawk is not working and trying to understand why! nawk -v t="internal_order" '/SAP_RM_ADMIN_SCHEMA/ && ("" toupper(t)) || /SAP_RM_ADMIN_SCHEMA/ && ("" tolower(t))' PBFD100.ksh My intention is to retrieve the line containing SAP_RM_ADMIN_SCHEMA.internal_order but its just not... (6 Replies)
Discussion started by: anduzzi
6 Replies

4. Shell Programming and Scripting

Can I use nawk -v with two or more variables?

Hi, Is it possible in awk/nawk to pass two or more variables in the -v flag? That is: X=1 Y=2 nawk -v X=$X Y=$Y..... Thanks in advance. (7 Replies)
Discussion started by: daytripper1021
7 Replies

5. Shell Programming and Scripting

nawk - Unable to use 2 variables for NR range

Hi, I need to break an input file into multiple output files. The number of output files is decided by a maximum record count allowed for each file. Hence I am using the nawk command to recursively retrieve a range of lines from an input file and write them to output files. But I am unable to... (3 Replies)
Discussion started by: ragz_82
3 Replies

6. Shell Programming and Scripting

Passing the nawk variables to the shell

nawk '($1 ~ "1000") && ($1 ~ "5665" ) { sub ($6,"89");flag =1;print }' old.txt >> new.txt I want to set a flag in awk , if the both conditions are met. I want to pass this flag to shell Can anyone please help me on this (1 Reply)
Discussion started by: prav076
1 Replies

7. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

8. Shell Programming and Scripting

I can't seem to pass variables properly into a nawk statement

Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to. The goal: -to... (6 Replies)
Discussion started by: DeCoTwc
6 Replies

9. Shell Programming and Scripting

nawk - Passing variables

Hi, I am passing the varibale using nawk -v to search the pattern from the file. But this variable is not accepting. I couldn't get the crrect output. Help me regarding..... nawk -v PGMNAME="$prog" ' { $0 ~ /PGMNAME/ { .................. ................. ... (3 Replies)
Discussion started by: sharif
3 Replies

10. Shell Programming and Scripting

Assigning nawk output to variables

I do a lot of command line scripting to capture data from files or other command output. I've checked in a number of Unix and scripting books but for the life of me I can't find out how to asign field data from nawk output into variables that I can manipulate later. For example, reading a two... (6 Replies)
Discussion started by: steveje0711
6 Replies
Login or Register to Ask a Question