multiple array


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers multiple array
# 1  
Old 01-22-2008
Network multiple array

we are using Linux Red hat version 9 and using bash shell .

Can any one help me in passing Name field interactivly and search the names from the data??Say I have
ARTHUR, SMITH, DANIS, CHARLES,GEORGE and likewise names in the
address's data and I want to search the same from the awk script .
i.e. I may want to pass two names or sometime five names :

echo -n 'Enter the Names you want to search:' >/dev/tty
read nam
awk '{ }' addr-dat > nnames

We can pass the name within the scripts but I want it to be flexible , I dont want hard-coding the name within the script but want to pass it from
the outside and it may be three or five names .

Thanks in advance .Smilie
# 2  
Old 01-22-2008
Well, I don't use bash, I use korn (one of the main reasons being array manipulation, I use arrays a lot), and in korn is really simple. Maybe this will help you figure it out in bash.
This basically takes whatever you enter and makes it an array, regardless of the number of names you enter at the "tell me" prompt.
Code:
#!/usr/bin/ksh
echo "tell me: "
read NAMES
set -A LIST $(echo ${NAMES})

Now that you have the LIST array, then you can loop it and pass each element to awk or grep or whatever, regardless of how many names you have.

Code:
for x in $(echo ${LIST[*]}); do
...your commands...
done

# 3  
Old 01-27-2008
Network multiple array

Thanks lot system shock but sorry I have not eloborated it fully,

What I wanted is that can we place the name simulteneolsy??May it be
two , three ,four or five.

i.e.
if ( nam=='$1'|| nam=='$2' || nam=='$3' )
{
script
}' input file name > o/p file name

with one by one it will take more as the data is very large ??

Thanks in advance .Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

ksh array updated by multiple scripts

Hello! Is it possible to update an array created in a ksh script by a child script that was spawned by the parent? So, if I have... #!/bin/ksh set -A myArray "Zero" "One" "Two" echo "0: ${myArray}" echo "1: ${myArray}" echo "2: ${myArray}" ./second_script.ksh ${myArray } echo... (2 Replies)
Discussion started by: garskoci
2 Replies

2. Shell Programming and Scripting

Array in awk outputs multiple values

Disclaimer: OP is 100% Awk beginner. I use this code on ASCII files I need to report against. awk 'BEGIN { tokens = 0 tokens = 0 tokens = 0 } { for (token in tokens) { if ($1 == token){print $0; tokens++;}}} END {for (token in tokens){ if( tokens ==... (1 Reply)
Discussion started by: alan
1 Replies

3. UNIX for Dummies Questions & Answers

need [HELP] sum array multiple files

Hi.. I'm very newbie here.. I wonder if somebody can help me.. I have multiple directories with same out file name for each directories.. ./dirA/out.dat ./dirB/out.dat ./dirC/out.dat ..and so on.. for ./dirA/out.dat here is the structure content : for ./dirB/out.dat the same... (4 Replies)
Discussion started by: agiantz
4 Replies

4. Shell Programming and Scripting

need [HELP] sum array multiple files

Hi.. I'm very newbie here.. I wonder if somebody can help me.. I have multiple directories with same out file name for each directories.. ./dirA/out.dat ./dirB/out.dat ./dirC/out.dat ..and so on.. for ./dirA/out.dat here is the structure content : for ./dirB/out.dat the same... (6 Replies)
Discussion started by: agiantz
6 Replies

5. Shell Programming and Scripting

Multiple Variables in Array from Existing Directories

I would like to extract directories from a specific place and keep them into an array of variables to run functions into it. Example, bash-3.00$ls adrian bryan caren derrick I want to keep each directory names into a variable adrian --> document bryan --> document caren --> document... (3 Replies)
Discussion started by: lynxlee
3 Replies

6. Shell Programming and Scripting

Multiple array problem in NAWK

I HAD these 2 files: file1 pictures.txt 5 ref2313 4 ref2345 3 ref5432 2 ref4244 1 dance.txt 6 ref2342 5 ref2352 4 ref0695 3 ref5738 2 ref4948 1 treehouse.txt 6 ref8573 5 ref3284 4 ref5838 3 ref4738 2 ref4573 1 file2 pictures.txt 1 3 dance.txt 2 4 treehouse.txt 3 5 what I... (1 Reply)
Discussion started by: linuxkid
1 Replies

7. Shell Programming and Scripting

Awk multiple variable array: comparison

Foo.txt 20 40 57 50 22 51 66 26 17 15 63 18 80 46 78 99 87 2 14 14 51 47 49 100 58 Bar.txt 20 22 51 15 63 78 99 55 51 58 How to get output using awk 20 22 57 50 51 15 26 17 63 78 80 46 99 55 - - 51 58 49 100 (5 Replies)
Discussion started by: genehunter
5 Replies

8. UNIX for Dummies Questions & Answers

Define multiple expression to single array?

This is fine and workinga = "A/A" How to define some thing like this ??? a = "A/A" or "T/T or some thing else (2 Replies)
Discussion started by: stateperl
2 Replies

9. UNIX for Dummies Questions & Answers

Help in Array looping and creating multiple lines

hi Gurus, I'm a newbie in scripting please check my script if this is correct. I think there's something wrong with it but I;m not sure. I'm trying to create multiple lines using awk from external xml files but i want to add additonal info in the data manually Since i don't knwo how to... (0 Replies)
Discussion started by: sexyTrojan
0 Replies

10. Shell Programming and Scripting

multiple 'if' statements out of array

I want to do multiple comparisons on a series of numbers from an array: I send the numbers in file1 through want to print out some info from file2 based on some conditions. The syntax just isn't correct??? awk ' NR==FNR{ a=$0 next ... (2 Replies)
Discussion started by: dcfargo
2 Replies
Login or Register to Ask a Question