AWK variable substitute issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK variable substitute issue
# 1  
Old 01-03-2012
AWK variable substitute issue

dear,

I have below file called folderlist.txt

Code:
# ParentFolder  environment_flag        SubFolders
triss            1                      checksum
bookstructure    1
fx               1                      checksum_GMDB

I have a script which which will create the folders under /home/date/<parent foler>/<subfolder> if the flag is 1

now at certain point of time, I need to verify whether the folders are created successfully or not
I have below awk script which checks perfectly alright if I don't pass the home and date as variable.
If I start making it dynamic by passing these two valuses then awk messed up and not taking these substitue properly.

Code:
AP_cubedata=/home
cube_date=20120104

awk -v AP_cubedata="${AP_cubedata}" -v cube_date="${cube_date}" '/^[^#]/ {
c=split($3,a,"/") ;
for(n=1; n<=c; ++n) {
val=val"/"a[n];
rc=system("test -d AP_cubedata/cube_date/"$1"/"a[n])
if (rc != 0)
print "AP_cubedata/cube_date/"$1"/"a[n]"  NOT exist"
}val=""}' /home/conf/folderlist.txt >> ${logfile}

can anyone assist me where exactly I'm messing up???
# 2  
Old 01-03-2012
Try replacing
Code:
print "AP_cubedata/cube_date/"$1"/"a[n]"  NOT exist"

with
Code:
print AP_cubedata "/" cube_date "/" $1 "/" a[n] " NOT exist"

# 3  
Old 01-03-2012
thanks a lot the print is working fine now.
But what's wrong with
Code:
system

command it's dispalying not exist as output tho these folders are exist under that date folder.
(/home/date/)
# 4  
Old 01-03-2012
it's the same case:
Code:
rc=system("test -d AP_cubedata/cube_date/"$1"/"a[n])

Code:
rc=system("test -d "AP_cubedata"/"cube_date"/"$1"/"a[n])

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue when printing filename through cygwin using a variable with awk

Hi, If i were to do this an print out the file, it will show as it is in the command $ awk '/Privilege Use/ {P=0} /Object Access/ {P=1} P' AdvancedAudit.txt Object Access File System No Auditing Registry No Auditing Kernel... (1 Reply)
Discussion started by: alvinoo
1 Replies

2. Shell Programming and Scripting

Substitute variable inside nawk

Hi, I need to set "prd" in the below command to a unix variable nawk '/^#/ {next} FNR==NR {prd;next} !($0 in prd)' So, this is what i did fname=prd // unix shell variable nawk -v fname=$fname '/^#/ {next} FNR==NR {fname;next} !($0 in fname)'But the value of fname i.e "prd" is not... (8 Replies)
Discussion started by: mohtashims
8 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. Shell Programming and Scripting

Issue with AWK using a variable

Hi, I am doing an AWK in ksh as below with the string to search to be read from variable but for some reason there is no output. It works when I hard code it. awk 'substr($0,22,6)=="${VAR}"' XXX.txt' >YYY.txt On reading other posts I tried below option, 'substr($0,22,6)=="/"${VAR}/""' ... (3 Replies)
Discussion started by: junnujayz
3 Replies

5. Shell Programming and Scripting

AWK Variable assignment issue Ksh script

Hi There, I am writing a ksh script which assigns variable values from file "A" and passes that variables to file "B". While passing the parameters an additional "$" sign is being assigned to awk -v option. Could any one help me with this please. #!/bin/ksh head -1... (3 Replies)
Discussion started by: Jeevanm
3 Replies

6. Shell Programming and Scripting

awk substitute variable value in nth field

I have a large csv file that looks like this: The 3rd field is a unix time stamp that I want to convert to human readable. I wrote a bash script with this code: IFS=$',' cat $1 | while read ID user DATE text flags read; do echo -e "$ID,$user,$(date -d @$DATE),$text,$flags,$read... (3 Replies)
Discussion started by: stumpyuk
3 Replies

7. Shell Programming and Scripting

substitute variable in bash

hi all, Assume that i a having the following three lines in an executable file #/bin/bash a=Tue Tue=1 When i give echo $a the value should be 1, how to do this. Your suggestions please. Thanks in advance, Anish (4 Replies)
Discussion started by: anishkumarv
4 Replies

8. Shell Programming and Scripting

substitute variable for values in perl

hi all, how do i assign values passed in from command line to and sql statement in perl ?? e.g i want to assign :name1 and :Name2 to be whatever is passed into the perl script command line my $sqlStr = "select * from test_table where column1 = upper(nvl(:name1, name1 )) and column2... (1 Reply)
Discussion started by: cesarNZ
1 Replies

9. UNIX for Dummies Questions & Answers

Substitute Variable

Can anyone tell me what is the purpose of a substitute variable in the unix programming language and give an example where it may be used? Thanks! (0 Replies)
Discussion started by: mmg2711
0 Replies

10. Shell Programming and Scripting

Substitute variable values

Hi, I am trying to redefine the value of a variable based on another variable value. And I want to read in my variables from a enviroment file in the end -- at least I think so. But 1st here's what I want I need to get working: var_1="11 10 9 8 7 6 5 4 3 2 1" var_2=3 var_3=4 So I want... (12 Replies)
Discussion started by: John Rihn
12 Replies
Login or Register to Ask a Question