Shell script to compare ,diff and remove betwen 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to compare ,diff and remove betwen 2 files
# 1  
Old 02-19-2013
Code Shell script to compare ,diff and remove betwen 2 files

Hi Friends Need your expertise.

Command to check the difference and compare 2 files and remove lines . example

File1 is master copy and File2 is a slave copy . whenever i change, add or delete a record in File1 it should update the same in slave copy . Can you guide me how can i accomplish this.


File1

Code:
1234
4567
8923


File2

Code:
1234
4567
8923
7879

.....
File2 has 7879 extra line and want to delete that line. and compare 2 files and it should be a same copy by checking wc -l File1 File2.

Thanks in advance

Last edited by joeyg; 02-19-2013 at 03:19 PM.. Reason: Please wrap commands and data with CodeTags
# 2  
Old 02-19-2013
Perhaps I do not understand, but
if file2 is supposed to be the same as file1, why not

Code:
cp file1 file2

This User Gave Thanks to joeyg For This Post:
# 3  
Old 02-20-2013
Thanks friend sometimes simple things become complicated. You gave a good idea to solve the problem. appreciate it. I knew the answer but this answer gave me another idea...Joeyg
# 4  
Old 02-20-2013
You can generate an ex script to modify the copy back in sync using diff -e. This can be good for sending small changes to a big file over slow networks.

Now, if you have a master file and 2 children with different changes, you can generate an ex script to put both changes in the master using diff3 -e Think parallel development changes merge.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Howto compare the columns of 2 diff tables of 2 different schemas in UNIX shell script

HI All, I am new to Unix shell scripts.. Could you please post the unix shell script for for the below request., There are two different tables(sample1, sample2) in different schemas(s_schema1, s_schema2). Unix shell script to compare the columns of two different tables of two... (2 Replies)
Discussion started by: Rajkumar Gopal
2 Replies

2. Shell Programming and Scripting

Compare two files using shell script

Hi i want to compare two files and i need the o/p of only difference here the files file1 achilles aedxbepo aedxbwdm01 aedxbwdm02 albedo amarice ambrister anakin anton argon artephius asgard avatar aymara (10 Replies)
Discussion started by: venikathir
10 Replies

3. Shell Programming and Scripting

Shell script to compare two files

I have two files; file A and file B. I need all the entries of file A to be compared with file B line by line. If the entry exists on file B, then save those on file C; if no then save it on file D Note :- all the columns of the lines of file A need to be compared, except the last two columns... (8 Replies)
Discussion started by: ajiwww
8 Replies

4. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

5. Shell Programming and Scripting

Using Diff to Compare 2 files

Hi I've been trying various methods that I have found online with regards to comparing 2 files using the diff command. Nothing seems to work. The problem is that I'm not too familiar with the proper syntax. Can you please assist me. Here is my script: #!/bin/bash awk -F',' -v file1="$1"... (9 Replies)
Discussion started by: ladyAnne
9 Replies

6. Shell Programming and Scripting

compare two files, diff the result

Hi Everyone, 1.txt 00:01:01 asdf 00:33:33 1234 00:33:33 0987 00:33:33 12 00:33:33 444 2.txt vvvv|ee 444|dd33|ee dddd|ee 12|ee 3ciur|fdd the output should be: (6 Replies)
Discussion started by: jimmy_y
6 Replies

7. UNIX and Linux Applications

How to compare two files using shell script

hi experts please help me to compare two files which are in different directory file1<file will be master file> (/home/rev/mas.txt} ex x1 x2 file2 <will be in different folder> (/home/rev/per/.....) ex x3 x4 the filesinside per folder i need to compare with master file... (1 Reply)
Discussion started by: revenna
1 Replies

8. Shell Programming and Scripting

Compare two files and output diff to third file

I have made several attempts to read two files of ip addresses and eliminate records from file1 that are in file2. My latest attempt follows. Everything works except my file3 is exactly the same as file1 and it should not be. # !/usr/bin/bash # # NoInterfaces # Utility will create a file... (8 Replies)
Discussion started by: altamaha
8 Replies

9. Shell Programming and Scripting

compare 2 coloum of 2 diff files using perl script

Hi, i am new to perl scripting.. i am still learing it.. i am asked to write a perl script which should compare 2 coloums of 2 different files. if those 2 coloumn are same the script should store the both the lines in 2 diff files. these are files, file 1: 21767016 226112 char 19136520... (3 Replies)
Discussion started by: vasuki
3 Replies
Login or Register to Ask a Question