LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-07-2014, 01:42 AM   #1
kathirvel
Member
 
Registered: Jan 2011
Location: Bangalore
Distribution: RHEL,OEL
Posts: 57

Rep: Reputation: 0
I need one shell script to compare two files.


I want one shell script to compare two files by picking line in first file and compare that file in another file return the output and reversal as well...

I will update the input file.

filename :- df_pre

10.224.164.132:/export/auohscabo31_42a_os/home /home
10.224.164.132:/export/auohscabo31_42a_os/oem /oem
10.224.164.132:/export/auohscabo31_42a_os/root /
10.224.164.132:/export/auohscabo31_42a_os/tmp /tmp
10.224.164.132:/export/auohscabo31_42a_os/usr /usr
10.224.164.132:/export/auohscabo31_42a_os/var /var
adc08ntap17-bkp:/vol/aoh_17a_ftp/ohs_ftp/cabo /interface
adc08ntap17-bkp:/vol/aoh_17a_hwmig/cabo /mig-os
adc08ntap17-bkp:/vol/aoh_17a_upgrade/upgrade /autofs/upgrade
adc08ntap18-bkp:/vol/aoh_18a_admin/ptsadmin /ptsadmin
adc08stor14-bkp:/export/cabo_ood_14/ood_repository /ood_repository
adc08stor14-bkp:/export/cabo_ood_14/scratch /scratch
adc09stor05-nas:/export/archive_05/dcab1i_arch /dcab1i/arch
adc09stor06-nas:/export/dcab1i_06/i31_oracle /dcab1i/oracle
adc09stor06-nas:/export/dcab1i_06/i31_oratmp /dcab1i/oratmp
adc09stor06-nas:/export/dcab1i_06/i_applcsf /dcab1i/applcsf
adc09stor06-nas:/export/dcab1i_06/i_backup /dcab1i/backup
adc09stor06-nas:/export/dcab1i_06/i_log /dcab1i/log
adc09stor06-nas:/export/dcab1i_06/i_oradata /dcab1i/oradata
adc09stor11-nas:/export/archive_11/scaboi_arch /scaboi/arch
adc09stor12-nas:/export/scaboi_12/i31_oracle /scaboi/oracle
adc09stor12-nas:/export/scaboi_12/i31_oratmp /scaboi/oratmp
adc09stor12-nas:/export/scaboi_12/i_applcsf /scaboi/applcsf
adc09stor12-nas:/export/scaboi_12/i_backup /scaboi/backup
adc09stor12-nas:/export/scaboi_12/i_log /scaboi/log
adc09stor12-nas:/export/scaboi_12/i_oradata /scaboi/oradata
adc09stor19-nas:/export/archive_19/tcab1i_arch /tcab1i/arch
adc09stor20-nas:/export/tcab1i_20/i31_oracle /tcab1i/oracle
adc09stor20-nas:/export/tcab1i_20/i31_oratmp /tcab1i/oratmp
adc09stor20-nas:/export/tcab1i_20/i_applcsf /tcab1i/applcsf
adc09stor20-nas:/export/tcab1i_20/i_backup /tcab1i/backup
adc09stor20-nas:/export/tcab1i_20/i_log /tcab1i/log
adc09stor20-nas:/export/tcab1i_20/i_oradata /tcab1i/oradata
adc09stor36-nas:/export/emcontainer1_36/auohscabo31_oem1 /oem1
tmpfs /dev/shm

---------------------------------------

filename :- df_post

10.224.164.13:/vol/auohscabo31_42a_os/home /home
10.224.164.13:/vol/auohscabo31_42a_os/oem /oem
10.224.164.13:/vol/auohscabo31_42a_os/root /
10.224.164.13:/export/auohscabo31_42a_os/tmp /tmp
10.224.164.13:/export/auohscabo31_42a_os/usr /usr
10.224.164.13:/export/auohscabo31_42a_os/var /var
adc08ntap17-bkp:/vol/aoh_17a_ftp/ohs_ftp/cabo /interface
adc08ntap17-bkp:/vol/aoh_17a_hwmig/cabo /mig-os
adc08ntap17-bkp:/vol/aoh_17a_upgrade/upgrade /autofs/upgrade
adc08ntap18-bkp:/vol/aoh_18a_admin/ptsadmin /ptsadmin
adc08stor14-bkp:/export/cabo_ood_14/ood_repository /ood_repository
adc08stor14-bkp:/export/cabo_ood_14/scratch /scratch
adc09stor05-nas:/export/archive_05/dcab1i_arch /dcab1i/arch
adc09stor06-nas:/export/dcab1i_06/i31_oracle /dcab1i/oracle
adc09stor06-nas:/export/dcab1i_06/i31_oratmp /dcab1i/oratmp
adc09stor06-nas:/export/dcab1i_06/i_applcsf /dcab1i/applcsf
adc09stor06-nas:/export/dcab1i_06/i_backup /dcab1i/backup
adc09stor06-nas:/export/dcab1i_06/i_log /dcab1i/log
adc09stor06-nas:/export/dcab1i_06/i_oradata /dcab1i/oradata
adc09stor11-nas:/export/archive_11/scaboi_arch /scaboi/arch
adc09stor12-nas:/export/scaboi_12/i31_oracle /scaboi/oracle
adc09stor12-nas:/export/scaboi_12/i31_oratmp /scaboi/oratmp
adc09stor12-nas:/export/scaboi_12/i_applcsf /scaboi/applcsf
adc09stor12-nas:/export/scaboi_12/i_backup /scaboi/backup
adc09stor12-nas:/export/scaboi_12/i_log /scaboi/log
adc09stor12-nas:/export/scaboi_12/i_oradata /scaboi/oradata
adc09stor19-nas:/export/archive_19/tcab1i_arch /tcab1i/arch
adc09stor20-nas:/export/tcab1i_20/i31_oracle /tcab1i/oracle
adc09stor20-nas:/export/tcab1i_20/i31_oratmp /tcab1i/oratmp
adc09stor20-nas:/export/tcab1i_20/i_applcsf /tcab1i/applcsf
adc09stor20-nas:/export/tcab1i_20/i_backup /tcab1i/backup
adc09stor20-nas:/export/tcab1i_20/i_log /tcab1i/log
adc09stor20-nas:/export/tcab1i_20/i_oradata /tcab1i/oradata
adc09stor36-nas:/export/emcontainer1_36/auohscabo31_oem1 /oem1
tmpfs /dev/shm

There are parts in the file , first part is a device and second is a mount point.

Device name : Mount Point:
------------- ---------------
adc09stor36-nas:/export/emcontainer1_36/auohscabo31_oem1 /oem1





This both files should be compared and return the output missing lines.

Thanks in advance.

kathirvel.S

Last edited by kathirvel; 01-07-2014 at 01:46 AM.
 
Old 01-07-2014, 01:46 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,468
Blog Entries: 6

Rep: Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409
How about sdiff -s first_file second_file?
 
Old 01-07-2014, 07:43 AM   #3
kathirvel
Member
 
Registered: Jan 2011
Location: Bangalore
Distribution: RHEL,OEL
Posts: 57

Original Poster
Rep: Reputation: 0
Hi astrogeek,

Thanks for the reply, The command is helpful. But my concern is output should be customized.

For example,

df_pre is the mount points details before reboot.
df_post is the mount points details after reboot.

see the below output.. I just swapped lines but I got the difference though both files have the same lines.This should not be given difference when both files has the same line.
[root@kathir1 kathir]# sdiff -s df-pre df-post
| adc08ntap17-bkp:/vol/aoh_17a_upgrade/upgrade /autofs/upgrade
> adc08ntap18-bkp:/vol/aoh_18a_admin/ptsadmin /ptsadmin
> adc08stor14-bkp:/export/cabo_ood_14/ood_repository /ood_repos
<
adc08ntap17-bkp:/vol/aoh_17a_upgrade/upgrade /autofs/upgrade <
adc08ntap18-bkp:/vol/aoh_18a_admin/ptsadmin /ptsadmin <
adc08stor14-bkp:/export/cabo_ood_14/ood_repository /ood_repos <
[root@kathir1 kathir]#

I want to display these mount points was there before mount point and these mounted extra after activity like that.

Hope with this command I can do that.But still I want a clear idea to be compared perfectly. Because in customer environment if this scripts works fine we don't need to check manually while doing migrations.

If you have idea give me pls....

Thanks,
Kathirvel.S

Last edited by kathirvel; 01-07-2014 at 07:48 AM.
 
Old 01-07-2014, 09:00 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,530

Rep: Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897
You will need to sort the files prior to comparing
 
Old 01-07-2014, 09:19 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,098

Rep: Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381
Quote:
Originally Posted by kathirvel View Post
Hi astrogeek,
Thanks for the reply, The command is helpful. But my concern is output should be customized. For example,

df_pre is the mount points details before reboot.
df_post is the mount points details after reboot.

see the below output.. I just swapped lines but I got the difference though both files have the same lines.This should not be given difference when both files has the same line.
[root@kathir1 kathir]# sdiff -s df-pre df-post
| adc08ntap17-bkp:/vol/aoh_17a_upgrade/upgrade /autofs/upgrade
> adc08ntap18-bkp:/vol/aoh_18a_admin/ptsadmin /ptsadmin
> adc08stor14-bkp:/export/cabo_ood_14/ood_repository /ood_repos
<
adc08ntap17-bkp:/vol/aoh_17a_upgrade/upgrade /autofs/upgrade <
adc08ntap18-bkp:/vol/aoh_18a_admin/ptsadmin /ptsadmin <
adc08stor14-bkp:/export/cabo_ood_14/ood_repository /ood_repos <
[root@kathir1 kathir]#

I want to display these mount points was there before mount point and these mounted extra after activity like that. Hope with this command I can do that.But still I want a clear idea to be compared perfectly. Because in customer environment if this scripts works fine we don't need to check manually while doing migrations.

If you have idea give me pls....
Spell out your words, please. And we understand what you WANT...but it appears that you are asking us to write a script for YOUR CUSTOMER. Can you post what YOU have written/tried so far, and tell us where you're stuck?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] efficient shell script to compare contents of files si-thk Linux - Newbie 13 09-06-2011 07:59 AM
Compare semicolon seperated data in 2 files using shell script novice82 Linux - Newbie 4 11-17-2009 05:26 PM
How to Compare Two files using shell script pooppp Linux - Networking 14 08-05-2008 03:35 AM
shell script: compare 2 files anhtt Programming 6 08-29-2007 02:39 AM
shell script to recursively "compare" all files in a directory... silex_88 Programming 3 05-12-2007 04:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration