looping and awk/sed help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting looping and awk/sed help
# 8  
Old 06-28-2005
yes the select statements come out great, but not the connections

you see I have 25 DB's and I want to compare them each to each other, and I figure the best way is like this

1-2
2-1
2-3
3-2
3-4
4-3
etc...

but I also want to just compare 1 table at a time in each of the 25 DB, what gets created now contains all tables.

I guess I could just grep this output intto a seperate sql file for each table_name?

Thanks so much for all the help so far,
Zelp
# 9  
Old 06-28-2005
ok, so do you want to permute amoung ALL the 25 tables and create a 'minus' selects for ALL of them?
Say you have 3 tables: t1, t2, t3
Do you need 6 permutations like so ?:
t1
minus
t2

t1
minus
t3

t2
minus
t1

t2
minus
t3

t3
minus
t1

t3
minus
t2

FYI: I've also fixed the script in the last posting - you may try it now.

Last edited by vgersh99; 06-28-2005 at 03:08 PM..
# 10  
Old 06-28-2005
here's the version with the permutations - you might want to improve the permutations part of as it is not the most efficient:
Code:
BEGIN {
    SEPlist=","
    schemasN=split("connection1 connection2 connection3 connection4", schemasA, " ")

  for(i=1; i <= schemasN; i++)
    for(j=1; j <= schemasN; j++)
      if ( i != j ) {
        perm[schemasA[i] SUBSEP schemasA[j]]
        perm[schemasA[j] SUBSEP schemasA[i]]
      }

}
FNR==NR { tbl[$1]; next}
{
  if ( $1 in tbl )
     out[$1] = ($1 in out) ? out[$1] SEPlist $2 : $2
}
END {
     for ( permI in perm ) {
       split(permI, from_toA, SUBSEP)
       for ( i in out) {
          outFile = i ".sql"
          printf("select %s from %s@%s\nminus\nselect %s from %s@%s\n\n#-----\n\n",  out[i], i, from_toA[1], out[i], i, from_toA[2] ) >> outFile
        }
     }
}


Last edited by vgersh99; 06-28-2005 at 04:41 PM.. Reason: segregate output based on connections/DBs
# 11  
Old 06-28-2005
WOW, you did it!

Thanks a ton.

now I can just awk that into a file, then grep the resulting file per each table_name and save that to individual SQLs per table.
# 12  
Old 06-28-2005
Quote:
Originally Posted by Zelp
WOW, you did it!

Thanks a ton.

now I can just awk that into a file, then grep the resulting file per each table_name and save that to individual SQLs per table.
you can do this without using grep - I've modified the last code posting.
# 13  
Old 06-28-2005
Thanks again, you are really on the ball!
# 14  
Old 06-29-2005
Hi Zelp,

F.Y.I ,Oracle has already created a comparison tool between schemas and databases.
You can invoke the module "Change Manager" from the OEM (Oracle Enterprise Manager) and run any comparison you want.

Best regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk nested looping?

I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk. The text file has a organization like so: Name Date Status Location (city, state, zip fields) Where each of these is on a separate line in... (1 Reply)
Discussion started by: kellyanneghj
1 Replies

2. UNIX for Beginners Questions & Answers

Looping and sed

Hi, I've got text files (say file1 and file2) in a directory (say directory1) with several columns like this: a b c d a b c de f g h e f g hI need to add a header to the files in directory1 and the names of the columns must contain an identifier from another text file (say file3) like this:... (4 Replies)
Discussion started by: zajtat
4 Replies

3. Shell Programming and Scripting

Help on looping using awk

I have the data like this: PONUMBER,SUPPLIER,LINEITEM,SPLITLINE,LINEAMOUNT,CURRENCY IR5555,Supplier1,1,1,83.1,USD IR5555,Supplier1,1,3,40.4,USD IR5555,Supplier1,1,6,54.1,USD IR5555,Supplier1,1,8,75.1,USD IR5556,Supplier2,1,1,41.1,USD IR5556,Supplier2,1,3,43.1,USD ... (3 Replies)
Discussion started by: jeffreybsu
3 Replies

4. Shell Programming and Scripting

AWK looping over 2 variables

I would like to loop over variables i and j consecutively, { a = -6.7 b = 7.0 c =0.1 { for (i = 0; i<=(b-a)/c; i++) for (j = 1; j<=(b-a)/c; j++) '$1<=(a+j*c)&&$1>=(a+i*c)' FILENAME > output_j '{print $2}' output_j > output_j_f } I essentially want to print the range of $1... (9 Replies)
Discussion started by: chrisjorg
9 Replies

5. Shell Programming and Scripting

looping in awk

How do I remove last comma? echo "xx yy zz" | awk 'BEGIN{FS=" "}{for (i=1; i<=NF; i++) printf "%s,", $i}'output: xx,yy,zz, required output: xx,yy,zz or (ideally!): xx, yy & zz many thanks in advance! (4 Replies)
Discussion started by: euval
4 Replies

6. Shell Programming and Scripting

Sed pattern space/looping conundrum

Although my sed skills are gradually developing, thanks in large part to this forum, I'm having a hard time dealing with pattern space and looping, which I suspect is what I'll need a better handle on to figure out my current issue, which is converting a multi line file like this: ... (4 Replies)
Discussion started by: tiggyboo
4 Replies

7. UNIX for Dummies Questions & Answers

Help with AWK looping

I'm trying to parse a configuration text file using awk. The following is a sample from the file I'm searching. I can retrieve the formula and recipe names easily but now I want to take it one step farther. In addition to the formula name, I would like to also get the value of the attribute... (6 Replies)
Discussion started by: new2awk
6 Replies

8. Shell Programming and Scripting

Looping and using Sed

Hi guys I having som problem trying to use sed to get a file and insert inside another one. I'll try to explain better. I have a base.txt and using sed(having a array variables) I'm chaging some strings inside this file and saving as base1.txt. until here okay. Then, I have to get this... (4 Replies)
Discussion started by: digobh
4 Replies

9. Shell Programming and Scripting

Awk: looping problem!

I am having a problem with awk when I run it with a loop. It works perfectly when I echo a single line from the commandline. For example: echo 'MFG009 9153852832' | awk '$2 ~ /^0-9]$/{print $2}' The Awk command above will print field 2 if field 2 matches 10 digits, but when I run the loop... (5 Replies)
Discussion started by: cstovall
5 Replies

10. UNIX for Advanced & Expert Users

Looping in awk

Can somebody give me a cleaner way of writing the following script. I was thinking that I could use a loop in the awk statement. It works fine the way it is but I just want the script to be cleaner. #!/usr/bin/sh for r in 0 1 2 3 4 5 6 do DAY=`gdate --date="${r} days ago" +%m\/%d\/%y`... (3 Replies)
Discussion started by: keelba
3 Replies
Login or Register to Ask a Question