Unable To access array in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable To access array in awk
# 1  
Old 12-17-2013
Unable To access array in awk

Hi,
i have the following code in which i am passing array tldn in awk using -v option & despite of that condition is not getting matched,can somebody suggest how to handle shell arrays in awk


Code:
tcount=(9875 9667)

awk -F"\t" -v ltldn="${tldn[*]}" 'NR==FNR {POSTPAIDMDNS[$1]=$2"|"$3;next}
                function ceil(val) { return (val == int(val)) ? val : int(val)+1}
                {
                        (substr($6,length($6)-9,10) in POSTPAIDMDNS && $7 !~ "[A-Z,a-z]" && (substr($20,length($20)-9,4) !~ ltldn))
                                print POSTPAIDMDNS[$6]
                ' FS="\t" PP.txt SS.MRC

IP file is as follows:
Code:
PP.txt:
9875222100      1000000426      15
9875040009      1000001576      1
1415101350      1000000300      1

SS.MRC:

386     130     23:59:31        11/30/2013      0       9875222100      919929377903    45      0       0       0       0       0       0       Ms   null     404001742760058 null    null    9667920916      null    null    IN      00:00:16        null    null    0       null    404009875008997 404009875008997      3501661179
603     130     23:59:49        11/30/2013      0       9875040009      919414288049    41      0       0       0       0       0       0       Ms   null     404001742768413 null    null    9137920523      null    null    IN      00:00:30        null    null    0       null    404009875008997 404009875008997      3501661261

# 2  
Old 12-17-2013
Any error msgs? The awk script as posted cannot execute correctly; tldn is not defined, tcount is not used, an if and a } is missing.
# 3  
Old 12-17-2013
Hi rudi,
Following is the updated code, also there is no error. Issue is array tldn content are not being matched correctly in awk when passed through -v option, is there any way out?

Code:
tldn=(9875 9667)

awk -F"\t" -v ltldn="${tldn[*]}" 'NR==FNR {POSTPAIDMDNS[$1]=$2"|"$3;next}
                function ceil(val) { return (val == int(val)) ? val : int(val)+1}
                {
                        (substr($6,length($6)-9,10) in POSTPAIDMDNS && $7 !~ "[A-Z,a-z]" && (substr($20,length($20)-9,4) !~ ltldn))
                                print POSTPAIDMDNS[$6]
                 }
                ' FS="\t" PP.txt SS.MRC

# 4  
Old 12-17-2013
Actually, the entire array's contents is assigned to a single variable which now holds all elements separated by $IFS's contents.
Try to reverse the match:
Code:
 ltldn !~ (substr($20,length($20)-9,4)

I still think an if is missing.
# 5  
Old 12-17-2013
Thanks Rudi...
Yes it seemed to work, one more question how reversing has helped as ltldn is still separated with two different values & value of each should match with the substr string.
Can you please throw light on this.
# 6  
Old 12-17-2013
In your case tldn = "9875 9667" and that substring is like "9137", so the match would read
Code:
 "9875 9667" !~ "9137"

which is true, or
Code:
 "9875 9667" !~ "9667"

which is false.
# 7  
Old 12-17-2013
Thanks a ton
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Unable to access to p5 9131 AIX system

Hi, I am very newbie with AIX system. I have changed the default IP address 192.168.2.147 of HMC1 to our LAN IP address. I can ping to the new ip address but unable to access to ASMI again with the new ip address. Is there a way that I can connect to the console or can reset to the default... (20 Replies)
Discussion started by: lilyn
20 Replies

2. AIX

P550 Unable to access Console

I have recently aquired the following machine: IBM,9113-550 Up until yesterday we could connect a dumb terminal to serial port 1 and get console login. However the dumb terminal died. We are now using a laptop with a null modem cable attached to serial port 1. This works perfectly for all of... (1 Reply)
Discussion started by: rsw7724
1 Replies

3. HP-UX

Unable to access TAR file

hi friends, I am using hp unix HP-UX B.11.11 .. Generally i do the compression to maintain the space availability . To compress the files first i used the TAR to collect all the files. it has done fine. when i am using command ls in the folder which has TAR file , it shows the TAR... (2 Replies)
Discussion started by: rdhaprakasam
2 Replies

4. Solaris

unable to access infodoc!!

Hi, I am refered to see Infodoc 80854. but I am not able to access from sun.com. Is there any precedure to view these?. Please guide me. Thanks in advance. (1 Reply)
Discussion started by: bpsunadm
1 Replies

5. Shell Programming and Scripting

Unable to access variable outside loop

I am unable to access the value set inside the loop from outside loop . Thought of taking this to forum , I had seen other replies also , where a pipe takes the execution to another shell and mentioned thats the reason we do not get the variable outside loop . But I am getting an issue and I am... (1 Reply)
Discussion started by: Armaan_S
1 Replies

6. Solaris

Unable to access 3500 FC array. Where is the problem?..

Hi, I have two Sun Fire V490 with Solaris 10 5/08, FC switch and two Sun StorageTek 3500 FC arrays. Each array is connected to switch and to one server at a time. In the last week I installed Solaris 10 5/08 on both servers and set up Sun Cluster, version 3.2. At wednesday all was fine - all... (7 Replies)
Discussion started by: Sapfeer
7 Replies

7. Shell Programming and Scripting

unable to access a variable not local to a while loop

I have a while loop like this cat ${filename} | while read fileline do ... done I need to access a variable value $newfile inside this while loop How will i do that?? (6 Replies)
Discussion started by: codeman007
6 Replies

8. UNIX for Dummies Questions & Answers

Access value outside awk or split value of array

Hello I am new to Unix. Please help me out. My Scenario: I am first collecting all the file names present in the directory with structure myinfo/yourinfo/supplierinfo I have four files with the names myCollector.java, yourCollector.java, someCollector.java, everyCollector.java. in the directory.... (1 Reply)
Discussion started by: jason.bean
1 Replies

9. Solaris

Unable to access home area

Good morning, I have a solaris 8 machine (Sunblade 1000) that is configured with NIS, I have checked everything I can think of to make sure everything is correctly configured which it appears it is but when I try to log into CDE it says it is unable to access my home area and it also does the... (1 Reply)
Discussion started by: Mr Pink
1 Replies

10. UNIX for Dummies Questions & Answers

unable to access hpfs/ntfs properly

i can't access my ntfs partition from one of my linux devices and can only acess it read only on the other... the two linux systems are Fedora core 4 and Ubuntu Hoary hedghog5*... all three are on a 40Gig drive ofcourse the windows partition is the primary partition but Fedora doesn't recognize ... (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question