Sponsored Content
Top Forums Shell Programming and Scripting Shell script compare all parameters in two files and display results Post 302472193 by ctsgnb on Tuesday 16th of November 2010 01:11:29 PM
Old 11-16-2010
This is hugly and not optimized but i think it does the work :

Code:
$ cat myfile
#!/usr/bin/ksh
f1=${1:-9i.ora}
f2=${2:-11g.ora}
printf "%-29s\t%40s\t%40s\n" "Param" "9i" "11g" >output.err
printf "%-29s\t%40s\t%40s\n" "Param" "9i" "11g" >output.ok
printf "%-29s\t%40s\t%40s\n" "Param" "9i" "11g" >output.all
while read p n
do
v9=$(grep $p $f1 | sed 's/.*=//' 2>/dev/null)
v11=$(grep $p $f2 | sed 's/.*=//' 2>/dev/null)
echo "p=$p v9=$v9 v11=$v11"
printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.all
case $n in
1)
        if [[ $v9 != $v11 ]]; then
echo "Warning : $p does not have the same values in $f1 and $f2 : missmatch !" >>output.err
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
        else
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.ok
        fi
;;
2)
if [[ -z "${v11}" ]]
then
        echo "Warning : $p is missing in file $f2" >>output.err
        printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
else
        printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.ok
fi
;;
3)
        if [[ -z "${v9}" ]]
        then
                echo "Warning : $p is missing in file $f1" >>output.err
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
        elif [[ -n "${v11}" ]]
        then
                echo "Warning : $p should not be in file $f2" >>output.err
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
        else
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.ok
        fi
;;
esac

done<listparam

Note that listparam should have lines looking like <parameter_name> <number_of_the_requirment>
Code:
$ cat listparam
db_block_size 1
db_cache_size 1
db_file_multiblock_read_count 1
open_cursors 1
cursor_sharing 1
background_dump_dest 1
core_dump_dest 1
user_dump_dest 1
diagnostic_dest 2
db_unique_name 2
memory_max_target 2
memory_target 2
pga_aggregate_target 3
java_pool_size 3
large_pool_size 3
shared_pool_size 3
$

This will generate 3 output :

output.all (for an overview of all the parameter value in each of the file '---' if not found or empty)

output.err (with an error message saying what's going wrong)

output.ok (containing parameters that do not match your error requirements)

feel free to change the default value for f1 and f2 to some other filename that match yours.


Code:
$ cat output.all
Param                                                                 9i                                             11g
db_block_size                                                       8192                                            8192
db_cache_size                                                  838860800                                     15286272000
db_file_multiblock_read_count                                         32                                             ---
open_cursors                                                        1000                                             800
cursor_sharing                                                       ---                                             ---
background_dump_dest              '/oradata/9I/system/trace/bdump'               '/oracle/11G/saptrace/background'
core_dump_dest                    '/oradata/9I/system/trace/cdump'               '/oracle/11G/saptrace/background'
user_dump_dest                    '/oradata/9I/system/trace/udump'                '/oracle/11G/saptrace/usertrace'
diagnostic_dest                                                      ---                                             ---
db_unique_name                                                       ---                                             ---
memory_max_target                                                    ---                                             ---
memory_target                                                        ---                                             ---
pga_aggregate_target                                          1572864000                                     13652041000
java_pool_size                                                       32M                                             ---
large_pool_size                                                      10M                                             ---
shared_pool_size                                               268435456                                      1785000000
$ cat output.err
Param                                                                 9i                                             11g
Warning : db_cache_size does not have the same values in 9i.ora and 11g.ora : missmatch !
db_cache_size                                                  838860800                                     15286272000
Warning : db_file_multiblock_read_count does not have the same values in 9i.ora and 11g.ora : missmatch !
db_file_multiblock_read_count                                         32                                             ---
Warning : open_cursors does not have the same values in 9i.ora and 11g.ora : missmatch !
open_cursors                                                        1000                                             800
Warning : background_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
background_dump_dest              '/oradata/9I/system/trace/bdump'               '/oracle/11G/saptrace/background'
Warning : core_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
core_dump_dest                    '/oradata/9I/system/trace/cdump'               '/oracle/11G/saptrace/background'
Warning : user_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
user_dump_dest                    '/oradata/9I/system/trace/udump'                '/oracle/11G/saptrace/usertrace'
Warning : diagnostic_dest is missing in file 11g.ora
diagnostic_dest                                                      ---                                             ---
Warning : db_unique_name is missing in file 11g.ora
db_unique_name                                                       ---                                             ---
Warning : memory_max_target is missing in file 11g.ora
memory_max_target                                                    ---                                             ---
Warning : memory_target is missing in file 11g.ora
memory_target                                                        ---                                             ---
Warning : pga_aggregate_target should not be in file 11g.ora
pga_aggregate_target                                          1572864000                                     13652041000
Warning : shared_pool_size should not be in file 11g.ora
shared_pool_size                                               268435456                                      1785000000
$


Last edited by ctsgnb; 11-17-2010 at 06:52 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

How to compare two files using shell script

hi experts please help me to compare two files which are in different directory file1<file will be master file> (/home/rev/mas.txt} ex x1 x2 file2 <will be in different folder> (/home/rev/per/.....) ex x3 x4 the filesinside per folder i need to compare with master file... (1 Reply)
Discussion started by: revenna
1 Replies

2. UNIX for Dummies Questions & Answers

Create a shell script for write files with 2 parameters

Hello, I'm a newbie in shell script. So, i would like to create a shell script which take 2 IN parameters (PARAM1 and PARAM2). This script need to create 2 files as : I need to create this file /etc/apache2/sites-available/PARAM2 : <VirtualHost *:80> DocumentRoot "/home/PARAM1/www"... (0 Replies)
Discussion started by: chatlumo
0 Replies

3. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

4. Shell Programming and Scripting

How to write a shell script to display files in single path?

Hello friends, I am a script which dispalys a multiple files with their contents. for exm: suppose two file test1.txt and test2.txt. when I run my script it have to display the below O/P. test1.txt -rw-r----- 1 sranga staff 91 Sep 23 02:18 calc.sh -rw-r----- 1 sranga ... (2 Replies)
Discussion started by: sivaranga001
2 Replies

5. Shell Programming and Scripting

Shell script to compare two files

I have two files; file A and file B. I need all the entries of file A to be compared with file B line by line. If the entry exists on file B, then save those on file C; if no then save it on file D Note :- all the columns of the lines of file A need to be compared, except the last two columns... (8 Replies)
Discussion started by: ajiwww
8 Replies

6. Shell Programming and Scripting

Compare two files using shell script

Hi i want to compare two files and i need the o/p of only difference here the files file1 achilles aedxbepo aedxbwdm01 aedxbwdm02 albedo amarice ambrister anakin anton argon artephius asgard avatar aymara (10 Replies)
Discussion started by: venikathir
10 Replies

7. Shell Programming and Scripting

How to use awk shell script to compare and match two files?

Basically, I have two files dupestest.txt 152,153 192,193,194 215,216 290,291 2279,2280 2282,2283haftest.txt 152,ABBOTS ROAD 153,ABBOTS ROAD 154,ABBOTS ROAD 155,ABBOTS ROAD 156,ABBOTS ROAD 157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Discussion started by: amyc92
4 Replies

8. Shell Programming and Scripting

Using shell script to compare files and retrieve connections

Hello, I want to use shell script to generate network files (I tried with python but its taking too long). I have a list of nodes: node.txt LOC_Os11g37970 LOC_Os01g07760 LOC_Os03g19480 LOC_Os11g45740 LOC_Os06g08290 LOC_Os07g02800 I have an edge-list as well: edge.txt Source_node ... (2 Replies)
Discussion started by: Sanchari
2 Replies

9. Shell Programming and Scripting

Shell script to compare two files for duplicate..??

Hi , I had a requirement to compare two files whether the two files are same or different .... like(files contaisn of two columns each) file1.txt 121343432213 1234 64564564646 2345 343423424234 2456 file2.txt 121343432213 1234 64564564646 2345 31231313123 3455 how to... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

10. UNIX for Beginners Questions & Answers

Shell Script to Compare Files and Email the differences

Hi, I have 2 files abc.txt and bdc.txt. I am using $diff -y abc.txt bcd.txt -- compared the files side by side I would like to write a Shell Script to cmpare the files side by side and print the results( which are not matched) in a side by side format and save the results in another... (10 Replies)
Discussion started by: vasuvv
10 Replies
All times are GMT -4. The time now is 05:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy