Accessing shell arrays in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accessing shell arrays in awk
# 1  
Old 09-10-2008
Accessing shell arrays in awk

I am trying to pass a shell array I created to match on values amongst other things.

I have a sample:

#! /bin/ksh

i=0
for id in `cat id.lst`
do
IDs[$i]=$id
(( i=i+1 ))
done

cat sqloutput.txt | awk -F, -v ids=$ID '{

# Do stuff

}'

But it looks as if I cannot do this. Is there any way I can pass this array into awk in my shell script.
# 2  
Old 09-10-2008
Try this:

Code:
awk -F, 'NR==FNR{ids[i++]=$0;next}{#Do your stuff here...}' id.lst sqloutput.txt

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Accessing variable from awk program in shell

Hi, I want to access a variable outside the awk program. My program is as below:- I can not access the exact value of k (See the last line of the program). #!/usr/bin/sh j=10 k=1 #k is declared outside awk awk ' BEGIN { i=1; j1="'"$j"'" printf("\n ## Value of j1 is %d ##", j1); ... (2 Replies)
Discussion started by: shouvik.mitra
2 Replies

2. AIX

Accessing Oracle DB via Shell possible ?

At work we are using AIX 4.2 for the client. On this system, there is Oracle and kron, Bash and C shell. Is it possible to access Oracle via the shell to create/update tables ? There is this hourly data that we accumulate on the AIX and we manually copy the infos to Excel for stats. I thought... (2 Replies)
Discussion started by: Browser_ice
2 Replies

3. Shell Programming and Scripting

Accessing arrays in shell scripts

Hi All, I have an array in my script. For example, array=(file1.xml,file1-summary.xml,file2.xml,file2-summary.xml,file3.xml,file3-summary.xml); I am accessing the elements of the array by using the following code. len=${#array }; while ; do echo "${array}" done I want... (1 Reply)
Discussion started by: ananddr
1 Replies

4. Shell Programming and Scripting

Accessing awk array from shell

Hi, i want awk to read a file and place it's content into two arrays. When trying to read these arrays with a "for a in ${source_path} "-Loop it gives the right result. But when trying to access directly (/bin/echo ${source_path}) it doesn't work. I read "all "the awk threads in this forum and... (6 Replies)
Discussion started by: bateman23
6 Replies

5. Shell Programming and Scripting

shell / awk arrays

I have a bash shell script that sources a data file, the data file has array values such as: #--data file ---# sg_name="db1" sg_size="12892" sg_allow="50000" sg_name="db2" sg_size="12892" sg_allow="50000" export sg_name sg_size sg_allow #--end data file --# In my shell script... (8 Replies)
Discussion started by: lochraven
8 Replies

6. Shell Programming and Scripting

Problem in accessing variables outside shell

Hi, I have a shell script wherein i am doing some file operations and storing the data in some variables. I am exporting these variables as i need to use them outside shell. Then within the shell i am launching GDB session hoping that i will be able to access the exported variables in the GDB... (2 Replies)
Discussion started by: jsantosh
2 Replies

7. Shell Programming and Scripting

Accessing the parameters of a shell script

Hi, I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form -... (2 Replies)
Discussion started by: The Observer
2 Replies

8. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

9. Shell Programming and Scripting

Accessing Shell Variables in awk or sed

Hello, I wonder if it is possible to pass and use variables from shell environment into sed or awk. I am trying to achieve something similar to the following using sed or awk: var=some_regular_expression grep "$var" filename # Will extract lines from filename The following code,... (3 Replies)
Discussion started by: nasersh
3 Replies

10. Shell Programming and Scripting

accessing ksh variables from awk

hi everybody! i am running this ksh script for replacing a set of strings by another set of new ones. i am getting both these from a file. also, the strings that i want to replace, are sub-strings(can occur more than once in each chunk) in a big chunk of data that i have bulk-copied(bcp utility)... (1 Reply)
Discussion started by: trupti wagh
1 Replies
Login or Register to Ask a Question