Dealing with Double Loops, Arrays and GREP


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Dealing with Double Loops, Arrays and GREP
# 8  
Old 05-29-2012
That might have been nice to know many posts ago. You need to be more specific about what you have and what you want, so we don't have to play 20-questions to give you the right answer.

You can put the stuff I've given you together in a slightly different way to get what you want.
Code:
N=1

for X in ruby kate john
do
        for Y in smith brown green
        do
                grep "$X $Y" filename > file-$N.txt
                N=`expr $N+1`
        done
done

# 9  
Old 05-29-2012
Thanks again Corona688

I worked around the code you sent and I guess it is working perfectly now Smilie
my final results for now is

Code:
for X in ruby kate john
do	
	for Y in smith brow green
	do
		grep "$X.*$Y" test.txt > $X-$Y.txt
	done
done

you were right, no need for arrays Smilie

Thanks again for your time
# 10  
Old 05-29-2012
Quote:
Originally Posted by A-V
Thanks again Corona688

I worked around the code you sent and I guess it is working perfectly now Smilie
my final results for now is

Code:
for X in ruby kate john
do	
	for Y in smith brow green
	do
		grep "$X.*$Y" test.txt > $X-$Y.txt
	done
done

you were right, no need for arrays Smilie

Thanks again for your time
That's what I would have suggested in the first place if you'd said you'd wanted files like ruby-smith instead of file-1 and file-2. This is why you need to be specific in the first place, so we don't need to play 20-questions.
# 11  
Old 05-30-2012
you are right and thanx for your time

I learn how I can do things as I go along so I wasnt sure what i should do either
cheers
A-V
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For i in loops on 2 arrays

Hey , i have this script and i have these loops so it can find a match between 2 arrays : ARRAY_1=(one two three) ARRAY_2=(A B C) VAR='B' for NUMBERS in "${ARRAY_1}" do for LETTERS in "${ARRAY_2}" do if ];then VAR='LETTERS' ... (2 Replies)
Discussion started by: batchenr
2 Replies

2. Shell Programming and Scripting

Using grep with multiple loops in reading files

I am trying to read a file line by line and then search that line in another file and get a particular column from the second file. I have written this code.but its not working properly #!/bin/sh while read keyword in duplicate.txt do echo $keyword while read line do ... (7 Replies)
Discussion started by: Prachi Gupta
7 Replies

3. UNIX for Dummies Questions & Answers

Dealing with Empty files, AWK and Loops

I write this bit of code to calculate the mean and variance for all the files in one directory and print the mean and variance in a separate folder but with the same file name. FILES="data/*" for X in $FILES do name=$(basename $X) awk '{x=$0; s+=$0; n++} END{mean=s/n; for (i in x){ss... (20 Replies)
Discussion started by: A-V
20 Replies

4. Shell Programming and Scripting

GREP/CUT/AWK to Arrays

hi people, I have a text file containing data, seperated by TAB. I want to process this tab'ed data as variable. how can I assign this? Ex: Code: 11aaa 12000 13aaa 14aaa 15aaa 16aaa 17aaa 21aaa 22000 23aaa 24aaa 25aaa 26aaa 27aaa 31aaa 32000 33aaa 34aaa 35aaa 36aaa 37aaa... (1 Reply)
Discussion started by: gc_sw
1 Replies

5. Shell Programming and Scripting

Korn Shell programming (FTP, LOOPS, GREP)

Hello All, I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database. To this, I have to construct a loop that checks a specified folder for a file. If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Discussion started by: jonesdk5
2 Replies

6. Shell Programming and Scripting

conflict: "for" loops and double precision numbers

Hi folk, Hope you enjoy the summer. I am stock after one day working, the problems are the following: 1) I want to write a for loop in a shell script code that has a double precision step as: #!/bin/bash START=0.00001 STOP=0.001 for((i = START ; i< STOP ; i=2*i)) do echo "$i"... (1 Reply)
Discussion started by: habib
1 Replies

7. Shell Programming and Scripting

arrays and while loops in bash

hi guys, i have an array called ARRAY which has elements in it... i am trying to assign elements of ARRAY to master_array.. i get a =: command not found error.. i=0 while do ${master_array}=${ARRAY} ((i++)) done is there something i am missing? (4 Replies)
Discussion started by: npatwardhan
4 Replies

8. Shell Programming and Scripting

trying to learn for loops, and arrays at the same time

Ok, I've already completed the task this is for, but now I'm trying to go back and find more eloquent solutions for future reference. I have a report I've generated that is formatted like this: 1033 1 1079 4 1453 5 2205 6 1933 7 461 8 646 9 1655 12 975 13 1289 14 The first number is... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

9. Shell Programming and Scripting

korn shell "loops & arrays"

Hi, I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares. For example: file1 has a list of user ids (about 900) from the company's e-mail server. file2 has a list of user ids (about 50 or so) from... (7 Replies)
Discussion started by: muzica
7 Replies
Login or Register to Ask a Question