script to find whether the difference between two files in only additions but not modifications


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to find whether the difference between two files in only additions but not modifications
# 1  
Old 10-17-2012
script to find whether the difference between two files in only additions but not modifications

i basically have 2 files and sdiff of the files is given below
Code:
sdiff file1 file 2

control_file                                                    <
path INDEX                                                    <
size 613                                                        <
mode 0444                                                     <
mtime 1349253720                                           <
tag INDEX                                                       <
control_file                                                     <
path INFO                                                       <
size 1461                                                       <
mode 0444                                                     <
mtime 1349253720                                            <
tag INFO                                                        <
file                                                               file
path /opt/wli/bin/wlitool                                    path /opt/wli/bin/wlitool
type f                                                             type f
size 2869432                                                    size 2869432
cksum 3407447155                                            cksum 3407447155
mode 0555                                                       mode 0555
uid 0                                                              uid 0
gid 2                                                              gid 2
owner root                                                       owner root
group bin                                                          group bin
mtime 1349245905                                                mtime 1349245905
compression_type gzip                                         compression_type gzip
compression_state compressed                    compression_state compressed
compression_cksum 108833867                   compression_cksum 108833867
compressed_size 1033608                                  compressed_size 1033608
file                                                               file
path /opt/wli/examples                                 path /opt/wli/examples
type d                                                             type d
mode 0555                                                          mode 0555
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
file                                                               file
path /opt/wli/examples/Makefile                    path /opt/wli/examples/Makefile
type f                                                             type f
size 1448                                                          size 1448
cksum 3256497595                                          cksum 3256497595
mode 0444                                                          mode 0444
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
mtime 1303277732                                                   mtime 1303277732
compression_type gzip                               compression_type gzip
compression_state compressed                    compression_state compressed
compression_cksum 3904222039              compression_cksum 3904222039
compressed_size 602                                  compressed_size 602
file                                                               file
path /opt/wli/examples/README                  path /opt/wli/examples/README
type f                                                             type f
size 2455                                                          size 2455
cksum 2233918146                                                   cksum 2233918146
mode 0444                                                          mode 0444
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
mtime 1303277718                                                   mtime 1303277718
compression_type gzip                             compression_type gzip
compression_state compressed                compression_state compressed
compression_cksum 2362662275         compression_cksum 2362662275
compressed_size 971                                        compressed_size 971
file                                                               file
path /opt/wli/examples/api_flac_test.c path /opt/wli/examples/api_flac_test.c
type f                                                             type f
size 1000                                                          size 1000
cksum 2153029248                                                   cksum 2153029248
mode 0444                                                          mode 0444
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
mtime 1303277716                                                   mtime 1303277716
compression_type gzip                    compression_type gzip
compression_state compressed                  compression_state compressed
compression_cksum 707411327                compression_cksum 707411327
compressed_size 554                                                compressed_size 554
file                                                               file
path /opt/wli/examples/api_ibac_test.cpath /opt/wli/examples/api_ibac_test.c
type f                                                             type f
size 1120                                                          size 1120
cksum 3601281228                                                   cksum 3601281228
mode 0444                                                          mode 0444
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
mtime 1303277713                                                   mtime 1303277713
compression_type gzip                               compression_type gzip
compression_state compressed               compression_state compressed
compression_cksum 3423279039               compression_cksum 3423279039
compressed_size 577                                                compressed_size 577
file                                                               file
path /opt/wli/include                                              path /opt/wli/include
type d                                                             type d
mode 0555                                                          mode 0555
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
file                                                               file
path /opt/wli/include/api.h                         path /opt/wli/include/api.h
type f                                                             type f
size 1872                                                          size 1872
cksum 3504961863                                                   cksum 3504961863
mode 0444                                                          mode 0444
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
mtime 1303217807                                                   mtime 303217807
compression_type gzip                     compression_type gzip
compression_state compressed                 compression_state compressed
compression_cksum 870673336                compression_cksum 870673336
compressed_size 795                             compressed_size 795
file                                                               file
path /opt/wli/lib                                                  path /opt/wli/lib
type d                                                             type d
mode 0555                                                          mode 0555
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
file                                                               file
path /opt/wli/lib/libwliapi.so                 path /opt/wli/lib/libwliapi.so
type s                                                             type s
size 0                                                             size 0
mode 0555                                                          mode 0555
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
link_source libwliapi.so.1                       link_source libwliapi.so.1
file                                                               file
path /opt/wli/lib/libwliapi.so.1                       path /opt/wli/lib/libwliapi.so.1
type f                                                             type f
size 221168                                                        size 221168
cksum 4025653529                                                   cksum 4025653529
mode 0555                                                          mode 0555
uid 2                                                              uid 2
gid 2                                                              gid 2
owner bin                                                          owner bin
group bin                                                          group bin
mtime 1349245751                                                   mtime 349245751
compression_type gzip                               compression_type gzip
compression_state compressed               compression_state compressed
compression_cksum 98047186                   compression_cksum 98047186
compressed_size 70051                         compressed_size 70051

the only difference between the files expected is additions at the begining of the file, any existing content of the file asfter the new additions can only have changes to mtime, there might be case where in there are no additions to the file1 and only changes can be mtime..... can any one please help in writing a script for find out if there are any other change other than additions in the begining and mtime changes to the existing file ?



i am doing a diff of both the files
Code:
1,12d0
< control_file
< path INDEX
< size 613
< mode 0444
< mtime 1349253720
< tag INDEX
< control_file
< path INFO
< size 1461
< mode 0444
< mtime 1349253720
< tag INFO
114c102
< mtime 1303217807
---
> mtime 303217807
147c135
< mtime 1349245751
---
> mtime 349245751

.......can something be done using this diff output ?

Last edited by Scott; 10-17-2012 at 05:07 PM.. Reason: Please use code tags
# 2  
Old 10-17-2012
If you use diff -e, and upon output examination, if it is all additions, there will be no change or delete commands. It is not hard to parse an output of only additions in sed or awk.
Code:
$ echo '1
> 2
> 3
> 4' >a
$ echo '0
1
2
2A
3
4
4A' >b
$ diff -e a b                    
4a
4A
.
2a
2A
.
0a
0
.
$

You can sort the files and send to 'comm -23'. Column 1 should be empty, no lines in a not in b.

In shell, it is very hard to have two input files open, but I think you can using coshell extensions. PERL and other full languages can do it easily.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Script to find difference between 2 files by column

Hi , i am newbie to shell scripting and am trying to do the below job, A shell script to be run with a command like sh Compare.ksh file1.txt file2.txt 1 2 > file3.txt 1 2-are the key columns Consider the delimiter would be Tab or comma File 1: SK TEST NAME MATHS PHYSICS 21 1 AAA... (1 Reply)
Discussion started by: shakthi666
1 Replies

2. Shell Programming and Scripting

Script to find difference between 2 files by column

Hi , i am newbie to shell scripting and am trying to do the below job, A shell script to be run with a command like sh Compare.ksh file1.txt file2.txt 1 2 > file3.txt 1 2-are the key columns Consider the delimiter would be Tab or comma File 1: SK TEST NAME MATHS PHYSICS 21 1... (1 Reply)
Discussion started by: shakthi666
1 Replies

3. Shell Programming and Scripting

To find difference between two files on a whole

Hi, The requirement is to compare two files that has single column of records each. Comparison is to happen on a whole and not line by line. File1.txt 314589929 315611087 304924413 315989094 301171509 302984393 315609549 314593632 File2.txt 315611087 304924413 315989094 (2 Replies)
Discussion started by: anandek
2 Replies

4. UNIX for Advanced & Expert Users

Find difference between 2 files

I have 2 files as follows. file1.txt <cell>123</cell> <cell>345</cell> file2.txt <cell>123</cell> <cell>456</cell> out out should be output.txt <cell>456></cell> How do we achieve this> The difference betwenn the two files should be wirtten to the output file.. ... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

5. UNIX for Dummies Questions & Answers

Find difference between two files

I have two files as below File1: a b c d File2: a b When i find the difference the output would be c&d.. How can i get my requirement...pls help... Many thanks in advance (10 Replies)
Discussion started by: jagadish_gaddam
10 Replies

6. Solaris

Need help to find difference between two files

I need to find the difference between two files in UNIX. I tried diff, but couldn't get it right. There are two files: file1: apple mango strawberry banana grape file2: grape apple banana I need an output file like below: ... (11 Replies)
Discussion started by: kisaad
11 Replies

7. UNIX for Dummies Questions & Answers

Find difference in two files

Hola, Tengo un texto texto1.txt con el siguiente contenido: Malaga Cadiz Sevilla Hola Y otro .txt texto2.txt con: Malaga Cadiz Sevilla Cordoba Huelva quiero obtener en otro .txt la diferencia entre estos dos archivos: (14 Replies)
Discussion started by: danietepa
14 Replies

8. Emergency UNIX and Linux Support

to find difference between two files

I have a file which gets appended with records daily..for eg. 1st day of the month i get 9 records ,2nd day 9 records .....till the last day in the month...the no of records may vary...i store the previous days file in a variable oldfile=PATH/previousdaysfile....i store the current days file in a... (6 Replies)
Discussion started by: ganesh_248
6 Replies

9. Shell Programming and Scripting

script to compare first column of two files and find difference

Hi, I want to write a script which will compare the 1st column of both the files and will give the difference. e.g:- my 1st file contains: 89 /usr 52 /usr/local 36 /tmp 92 /opt 96 /home 27 /etc/opt/EMCom 1 ... (3 Replies)
Discussion started by: adityam
3 Replies

10. UNIX for Dummies Questions & Answers

list files with modifications <15 minutes

Good Afternoon Guys: we can use ls -l to find out the files and their modification time. however, how to list the files say which are modified 15 minutes before. we have find command which uses -mtime and -atime for modification and access timing. However, if we just be restricted to the current... (2 Replies)
Discussion started by: tom_k_mishra
2 Replies
Login or Register to Ask a Question