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
netip :01.99.22.10
username :herty
component : sds mgm tth
link file :
symbol : �$ %$
NEW FILE content will be
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 :
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
@bipinajith: won't work. It doesn't sync back in once there's one or more lines too many in either file. In this case, the component line shifts the entire OLD_FILE one down, never to come back in sync.
diff (magically?) does...
Well, that's a matter of opinion. Result of your code working on requestor's files:
Line 1 is different:
OLD_FILE: netip :01.99.22.10 NEW_FILE: netip:11.88.23.11
Line 2 is different:
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: NEW_FILE: link file : gge
Line 5 is different:
OLD_FILE: link file : NEW_FILE: symbol : �$ %$
Line 6 is different:
OLD_FILE: symbol : �$ %$ NEW_FILE:
You are right when you say line 5 etc. is different, but old line 6 equals new line 5, so a resync should take place (as does diff ). Else long files will be entirely different should line 1 be lost... The requestor's sample output vaguely alludes he/she wants resync.
Anyhow, I regretfully apologize for the harsh wording.
Thanks Bipinajith. your idea does works very well but my only concern is in output display i am getting even "/n". so am bit confussed here does it considering "/n" as well while comparing.
output looks like this :
./cmpconfig.sh OLD_FILE NEW_FILE
Line 1 is different:
OLD_FILE: netip :01.99.22.10 NEW_FILE: netip:11.88.23.11\n
Line 2 is different:
OLD_FILE: username :herty NEW_FILE: username : mmerty\n
Line 3 is different:
OLD_FILE: component : sds mgm tth NEW_FILE: \n
Line 4 is different:
OLD_FILE: NEW_FILE: link file : gge\n
Line 5 is different:
OLD_FILE: link file : NEW_FILE: symbol : �$ %$\n
Line 6 is different:
OLD_FILE: symbol : �$ %$ NEW_FILE: \n
Moreover, output shouldn't have displayed Line 5 and 6, since both line values are same. Even don't want to display \n at the end. Could you please tell me how to avoid this ?