Sponsored Content
Top Forums Shell Programming and Scripting script to find whether the difference between two files in only additions but not modifications Post 302717121 by DGPickett on Wednesday 17th of October 2012 02:43:23 PM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
XDIFF_STRING_DIFF(3)							 1						      XDIFF_STRING_DIFF(3)

xdiff_string_diff - Make unified diff of two strings

SYNOPSIS
string xdiff_string_diff (string $old_data, string $new_data, [int $context = 3], [bool $minimal = false]) DESCRIPTION
Makes an unified diff containing differences between $old_data string and $new_data string and returns it. The resulting diff is human- readable. An optional $context parameter specifies how many lines of context should be added around each change. Setting $minimal parameter to true will result in outputting the shortest patch file possible (can take a long time). PARAMETERS
o $old_data - First string with data. It acts as "old" data. o $new_data - Second string with data. It acts as "new" data. o $context - Indicates how many lines of context you want to include in the diff result. o $minimal - Set this parameter to TRUE if you want to minimalize the size of the result (can take a long time). RETURN VALUES
Returns string with resulting diff or FALSE if an internal error happened. EXAMPLES
Example #1 xdiff_string_diff(3) example The following code makes unified diff of two articles. <?php $old_article = file_get_contents('./old_article.txt'); $new_article = $_REQUEST['article']; /* Let's say that someone pasted a new article to html form */ $diff = xdiff_string_diff($old_article, $new_article, 1); if (is_string($diff)) { echo "Differences between two articles: "; echo $diff; } ?> NOTES
Note This function doesn't work well with binary strings. To make diff of binary strings use xdiff_string_bdiff(3)/xdiff_string_rabd- iff(3). SEE ALSO
xdiff_string_patch(3). PHP Documentation Group XDIFF_STRING_DIFF(3)
All times are GMT -4. The time now is 04:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy