I am writing a ksh to check for duplicate records in two different set of tables on oracle database, to get this i am running two plsql qurries at a time through the ksh, so the output of the qurries will be stored in variable say "SQL_STRING". So now to say if duplicate records exists in table or not i have to write a script which checks the count of the word "no rows selected" in the SQL_STRING variable.
One of our friend on UNIX.COM helped me with the code below which counts from a file instead of from a variable
For example the variable SQL_STRING has data as below:
no rows selected no rows selected
ora-1234 sql querry failed
no rows selected
Now we should look for the string "no rows selected" (note: it has spaces between) in the variable SQL_STRING and then store the count of the string in a variable.
for the above data the output should be 3 since the string "no rows selected" occurred three times.
Any help is appreciated.
Is this homework? Looks like a post I read earlier today.
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.
Please review the rules, which you agreed to when you registered, if you have not already done so.
More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.
This is not an home work, i am new to forums concept and to the unix too.
I have a situation at work where i need to compare two oracle tables and see wheatear we have duplicates or not. if duplicates exists then i should ftp those records to mainframe system and if no duplicates exists then should go to next step.
i have posted this question previously and got an answer to it, but once i started working on it i found some changes and then posted a new thread.
If the command you referenced is working, modulo the variable issue, then this will probably do the trick:
Depending on your needs, you could also just pipe the output of the database query command directly into awk and not worry about any size limits that the shell might put on the contents of a variable.
The 'n+0' in the print ensures that you get a number out. If the query returns no output, n will not have been set and the print will print a blank rather than 0; the n+0 forces it to print a zero.
---------- Post updated at 20:07 ---------- Previous update was at 19:39 ----------
As was pointed out in another post just a few minutes ago, if the SQL_STRING is empty, echo will still print a single newline so n should always be set. Caution never hurts though.
Last edited by agama; 09-01-2010 at 08:40 PM..
Reason: corrected typo
You are most welcome. I believe that it is most important to give the 'why' with the 'how,' and not just the 'how.' I also believe in commenting my code
Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument.
echo "FILE PROPERTY: $fileprops"
echo "PARAMETER3: $1"
if ; then
echo "We are Good. $line FILE is found to be INTACT !! "
else
echo... (2 Replies)
Input:
|Running the Rsync|Sun Oct 16 22:48:01 BST 2016
|End of the Rsync|Sun Oct 16 22:49:54 BST 2016
|Running the Rsync|Sun Oct 16 22:54:01 BST 2016
|End of the Rsync|Sun Oct 16 22:55:45 BST 2016
|Running the Rsync|Sun Oct 16 23:00:02 BST 2016
|End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
I have a large dataset with following structure;
C 0001 Carbon
D SAR001 methane
D SAR002 ethane
D SAR003 propane
D SAR004 butane
D SAR005 pentane
C 0002 Hydrogen
C 0003 Nitrogen
C 0004 Oxygen
D SAR011 ozone
D SAR012 super oxide
C 0005 Sulphur
D SAR013... (3 Replies)
Hi All,
I am trying to to compare a string variable with a string literal inside a loop but keep getting the
./testifstructure.sh: line 6:
#!/bin/sh
BOOK_LIST="BOOK1 BOOK2"
for BOOK in ${BOOK_LIST}
do
if
then echo '1'
else
echo '2'
fi
done
Please use next... (1 Reply)
Can someone tell me how I can do this?
e.g:
a=$(echo -e wert trewt ertert ertert ertert erttert
erterte
rterter
tertertert
ert)
How do i replace the STRING with $a?
I try this:
sed -i 's/STRING/'"$a"'/g' filename.ext
but this don' t work (2 Replies)
Hi All
I've very nearly finished this script I'm working on but have hit another idiots problem, after googling I can't see a solution for this one.
I have a while count loop that checks checks two consecutive values then increments the count by two.
What the script has to do is then check... (5 Replies)
I am writing ksh to check for duplicate records in two different set of tables on oracle database, to get this i am running two plsql qurries at a time through the ksh, so the output of the qurries will be stored in variable say "SQL_STRING". So now to say if duplicate records exists in table or... (3 Replies)
Hi ,
I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;"
... (4 Replies)
Hi,
i call my shell like:
my_shell "my project name"
my script:
#!/bin/bash -vx
projectname=$1
sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp
cp temp test_config_doxy
the following error occurres:
sed s/'PROJECT_NAME ... (2 Replies)