Sponsored Content
Top Forums Shell Programming and Scripting Script to compare 2 files and prints difference as output sidebyside Post 302755271 by Optimus81 on Saturday 12th of January 2013 11:20:23 AM
Old 01-12-2013
Script to compare 2 files and prints difference as output sidebyside

Hi All,

Am trying script to compare 2 files and print the difference found from old file to new file on line by line basis on side by side display.

Basically line by line comparision and files may contain blank line as well

I know we have compare/diff commands but i don't how to make them display the results side by side.

for ex : OLD_FILE content will be
Code:
netip :01.99.22.10
username :herty
component : sds mgm tth
 
link file : 
symbol : £$ %$

NEW FILE content will be
Code:
netip:11.88.23.11
username : mmerty
 
link file : gge
symbol : £$ %$

After running the script : ./scriptname OLD_FILE NEW FILE

Output should display like this :
Code:
line 1 is different :
OLD_FILE : netip :01.99.22.10      NEW FILE : netip:11.88.23.11
 
line 2 is diiferent : 
OLD_FILE : username :herty        NEW FILE : username : mmerty
 
line 3 is different :
OLD_FILE : component : sds mgm tth  NEW FILE  : 
 
line 4 is different :
OLD_FILE : link file :      NEW FILE : link file : gge

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to compare two files and to print the difference

suppose one file P1168S P2150L P85L Q597R R1097C Another file P2150L P85L Q597R R1097C R1379C R1587K Then output shud be R1379C R1587K thanks (5 Replies)
Discussion started by: cdfd123
5 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. UNIX for Dummies Questions & Answers

Compare Files and Output Difference

I have to compare two files for any differences, then output the lab and question number for any differences. This is what I currently have: diff lab2.txt lab2answer.txt > lab2compare.txt Though the output doesn't have to be sent to a .txt (or any sort of log), I found that easier, at least... (2 Replies)
Discussion started by: Joesgrrrl
2 Replies

4. Shell Programming and Scripting

Compare two columns in two files and print the difference

one file . . importing table employee 119 . . importing table jobs 1 2nd file . . importing table employee 120 . . importing table jobs 1 and would like... (2 Replies)
Discussion started by: jhonnyrip
2 Replies

5. UNIX for Dummies Questions & Answers

compare / difference between sub-sections of files

Hi there, I'm sure this question has been asked many times but I can't find any posts with information. How can I check the differences between say lines 20 - 200 in file1 and lines 420 - 600 in file2? Thanks in advance for any help! js (2 Replies)
Discussion started by: js8765
2 Replies

6. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

7. Shell Programming and Scripting

Compare two files and output difference, by first field using awk.

It seems like a common task, but I haven't been able to find the solution. vitallog.txt 1310,John,Hancock 13211,Steven,Mills 122,Jane,Doe 138,Thoms,Doe 1500,Micheal,May vitalinfo.txt 12122,Jane,Thomas 122,Janes,Does 123,Paul,Kite **OUTPUT** vitalfiltered.txt 12122,Jane,Thomas... (2 Replies)
Discussion started by: charles33
2 Replies

8. Shell Programming and Scripting

compare multiple files and get the difference

Hi all, i have 50 files .data should be same in these 50 files , so my task is to find the difference. i need a logic , which finds difference between all files and print in output file with file name where it found that difference . i tried below logic , but its not giving me what i want. let... (2 Replies)
Discussion started by: deepakiniimt
2 Replies

9. Shell Programming and Scripting

Compare two text files and output difference

Hi experts, I am trying to compare two text files and output the difference to another file. I'm not strictly looking for differences in text but additional text at the end of one file that isn't in another, so basically comparing the file 2 against file 1 and printing any additional text to... (9 Replies)
Discussion started by: martin0852
9 Replies

10. Shell Programming and Scripting

Script which telnets to a device, runs commands and prints output to a file

I am connecting to a device using telnet, I want my script to perform certain commands : ie- show device , show inventory..etc and write the output it sees from the terminal to a file. this is what I have got : #!/usr/bin/expect -- set running 1 spawn telnet <ip address> expect ... (1 Reply)
Discussion started by: samantha123
1 Replies
NUMDIFF(1)							   User Commands							NUMDIFF(1)

NAME
numdiff - compare similar files with numeric fields DESCRIPTION
Usage: numdiff -h|--help|-v|--version or numdiff [-s IFS][-a THRVAL[:RANGE|:RANGE1:RANGE2]][-r THRVAL[:RANGE|:RANGE1:RANGE2]][-2][-F NUM][-# NUM][-P][-N][-I][-c CURRNAME][-d C1C2][-t C1C2][-g N1N2][-p C1C2][-n C1C2][-e C1C2][-i C1C2][-X 1:RANGE][-X 2:RANGE][-E][-D][-b][-V][-O[NUM]][-q][-S][-z 1:RANGE][-z 2:RANGE][-Z 1:RANGE][-Z 2:RANGE][-m][-H][-f[NUM]][-T][-B][-l PATH][-o PATH] FILE1 FILE2 Compare putatively similar files line by line and field by field, ignoring small numeric differences or/and different numeric formats. RANGE, RANGE1 and RANGE2 stay for a positive integer value or for a range of integer values, like 1-, 3-5 or -7. The two arguments after the options are the names of the files to compare. The complete paths of the files should be given, a directory name is not accepted. The given paths cannot refer to the same file but one of them can be "-", which refers to stdin. Exit status: 1 if files differ, 0 if they are equal, -1 (255) in case of error -s, --separator=IFS Specify the set of characters to use to split the input lines into fields (The default set of characters is space, tab and newline). If IFS is prefixed with 1: or 2: then use the given character set only for the lines from the first or the second file respectively -a, --absolute-tolerance=THRVAL[:RANGE|:RANGE1:RANGE2] Set to THRVAL the maximum absolute difference permitted before that two numeric fields are regarded as different (The default value is zero). If a RANGE is given, use the specified threshold only when comparing fields whose positions lie in RANGE. If both RANGE1 and RANGE2 are given and have the same length, then use the specified threshold when comparing a field of FILE1 lying in RANGE1 with the corresponding field of FILE2 in RANGE2 -r, --relative-tolerance=THRVAL[:RANGE|:RANGE1:RANGE2] Set to THRVAL the maximum relative difference permitted before that two numeric fields are regarded as different (The default value is zero). If a RANGE is given, use the specified threshold only when comparing fields whose positions lie in RANGE. If both RANGE1 and RANGE2 are given and have the same length, then use the specified threshold when comparing a field of FILE1 lying in RANGE1 with the corresponding field of FILE2 in RANGE2 -2, --strict Consider two numerical values as equal only if both absolute and relative difference do not exceed the corresponding tolerance threshold -F, --formula=NUM Use the formula indicated by NUM to compute the relative errors. If 'NUM' is 0 use the classic formula. If 'NUM' is 1 compute the relative errors by considering the values in FILE1 as sample values. If 'NUM' is 2 compute the relative errors by considering the values in FILE2 as sample values. -#, --digits=NUM Set to NUM the number of digits in the significands used in multiple precision arithmetic -P, --positive-differences Ignore all differences due to numeric fields of the second file that are less than the corresponding numeric fields in the first file -N, --negative-differences Ignore all differences due to numeric fields of the second file that are greater than the corresponding numeric fields in the first file -I, --ignore-case Ignore changes in case while doing literal comparisons -c, --currency=CURRNAME Set to CURRNAME the currency name for the two files to compare. CURRNAME must be prefixed with 1: or 2: to specify the currency name only for the first or the second file -d, --decimal-point=C1C2 Specify the characters representing the decimal point in the two files to compare -t, --thousands-separator=C1C2 Specify the characters representing the thousands separator in the two files to compare -g, --group-length=N1N2 Specify the number of digits forming each group of thousands in the two files to compare -p, --plus-prefix=C1C2 Specify the (optional) prefixes for positive values used in the two files to compare -n, --minus-prefix=C1C2 Specify the prefixes for negative values used in the two files to compare -e, --exponent-letter=C1C2 Specify the exponent letters used in the two files to compare -i, --imaginary-unit=C1C2 Specify the characters representing the imaginary unit in the two files to compare -X, --exclude=1:RANGE Select the fields of the first file that have to be ignored -X, --exclude=2:RANGE Select the fields of the second file that have to be ignored -E, --essential While printing the differences between the two compared files show only the numerical ones -D, --dummy While printing the differences between the two compared files neglect all the numerical ones (dummy mode) -b, --brief Suppress all messages concerning the differences discovered in the structures of the two files -V, --verbose For every couple of lines which differ in at least one field print an header to show how these lines appear in the two compared files -O, --overview[=NUM] Display a side by side difference listing of the two files showing which lines are present only in one file, which lines are present in both files but with one or more differing fields, and which lines are identical. If 'NUM' is zero or is not specified, output at most 130 columns per line. If 'NUM' is a positive number, output at most 'NUM' columns per line. If 'NUM' is a negative number, do not output common lines and display at most -'NUM' columns per line. -q, --quiet, --silent Suppress all the standard output -S, --statistics Add some statistics to the standard output -z, --blur-if-numerical=1:RANGE Select the fields of the first file that have to be blurred during the synchronization procedure only if they turn out to be numeric -z, --blur-if-numerical=2:RANGE Select the fields of the second file that have to be blurred during the synchronization procedure only if they turn out to be numeric -Z, --blur-unconditionally=1:RANGE Select the fields of the first file that have to be unconditionally blurred during the synchronization procedure -Z, --blur-unconditionally=2:RANGE Select the fields of the second file that have to be unconditionally blurred during the synchronization procedure -m, --minimal During synchronization try hard to find a smaller set of changes -H, --speed-large-files During synchronization assume large files and many scattered small changes -f, --test-filter[=NUM] Run only the filter and then show the results of its attempt to synchronize the two files. If 'NUM' is zero or is not specified, output at most 130 columns per line. If 'NUM' is a positive number, output at most 'NUM' columns per line. If 'NUM' is a negative number, do not output common lines and display at most -'NUM' columns per line. -T, --expand-tabs Expand tabs to spaces in output while displaying the results of the synchronization procedure (meaningful only together with option -O or -f) -B, --binary Treat both files as binary files (only meaningful under Doz/Windoz) -l, --warnings-to=PATH Redirect warning and error messages from stderr to the indicated file -o, --output=PATH Redirect output from stdout to the indicated file -h, --help Show help message and predefined settings -v, --version Show version number, Copyright, Distribution Terms and NO-Warranty Default numeric format (for both files to compare): Currency name = "" Decimal point = `.' Thousands separator = `,' Number of digits in each thousands group = 3 Leading positive sign = `+' Leading negative sign = `-' Prefix for decimal exponent = `e' Symbol used to denote the imaginary unit = `i' COPYRIGHT
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Ivano Primi <ivprimi@libero.it> License GPLv3+: GNU GPL version 3 or later, see <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for numdiff is maintained as a Texinfo manual. If the info and numdiff programs are properly installed at your site, the command info numdiff should give you access to the complete manual. numdiff 5.6.0 January 2012 NUMDIFF(1)
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy