matching in loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching in loop
# 1  
Old 09-26-2012
matching in loop

hello all,

this is probably very simple for you guys but i am trying to achive something like below...i have 2 files...file 1 has entries like below
Code:
DB1:NS
DB2:NS
DB3:NS
DB4
DB5:NS

and file2 as below
Code:
DB1
DB2
DB5


i was to write a loop statment were if there is a matching entry from 2 file do nothing else echo things from file2....example is, if(from file1) DB1 = DB1(file 2) then do nothing/exit or else echo file2 info...

i came up with below...but dose not work...
Code:
export FILE1=/oracle/tmp/ns
for db in `egrep -i ":NS" $FILE1`
do
echo "processing database: $db"
if [ -f /oracle/tmp/file2 ]; then
cat /oracle/tmp/file | while read LINE; do
if $db = $LINE; then
exit
else
echo "....................NOW PROCESSING INNER DB $LINE"
fi
done
fi
done


Last edited by Franklin52; 09-27-2012 at 08:28 AM.. Reason: fixed code tags
# 2  
Old 09-26-2012
See if the below code is what you are looking to do:
Code:
$ cat find_match.sh
while IFS=":" read field1 field2
do
  grep -q $field1 t2
  if [ $? -eq 0 ]; then
    echo "$field1 found in t2"
  else
    echo "$field1 NOT found in t2"
  fi
done <t

$ cat t
DB1:NS
DB2:NS
DB3:NS
DB4
DB5:NS

$ cat t2
DB1
DB2
DB5

$ find_match.sh
DB1 found in t2
DB2 found in t2
DB3 NOT found in t2
DB4 NOT found in t2
DB5 found in t2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

4. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

5. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

6. Shell Programming and Scripting

AWK pattern matching on loop

Hi, I am still a beginner on shell scripting so please bear with me. What i am trying to do is filter my logfile based on some ID on field 24 which is defined in array. The filter result output will be moved to my log folder with the same name. The problem is when not using loop, this command... (2 Replies)
Discussion started by: howielim
2 Replies

7. Shell Programming and Scripting

matching user input to a text file loop?

until do read -p "Invalid cars. Try againa" cars1 done Ok i have the above code, im getting users input and if it doesnt match in the file the user has to try again untill its correct But when i run this it gives me an error saying ./Cars.bash: line 43: (2 Replies)
Discussion started by: gangsta
2 Replies

8. Shell Programming and Scripting

awk: matching and not matching

Hello all, simple matching and if not match problem that i can't figure out. file1 hostname: 30 10 * * * /home/toto/start PROD instance_name1 -p 00 9 * * * /home/toto/start PROD instance_name2 -p 15 8 * * * /home/toto/start PROD instance_name3 -p hostname2: 00 8 * * *... (5 Replies)
Discussion started by: maverick72
5 Replies

9. Shell Programming and Scripting

loop and extract matching filename

i am unable to exact matching filename in the loop. Filename.in file contains Customer_Product_ Information_Customer_Product_ sale_Product_ /home_dir contains files CUST_INFO_990090_1111.csv "1","Customer Product Detail","1000","salary" "1","Information Customer Product... (2 Replies)
Discussion started by: onesuri
2 Replies

10. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
Login or Register to Ask a Question