Comparing two .txt files in shell scripting...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing two .txt files in shell scripting...
# 8  
Old 06-30-2008
Quote:
Originally Posted by prakash123
it is also not working.it is only showing the common parts.
once again - go through 'man comm'.
# 9  
Old 06-30-2008
Hi,
comm is not working properly.for example take two small files like

file1.txt--My name is x
My name is Y

file2.txt--My name is


The command or shell script should be like that the result should be

x
Y


Thanks,
Prakas
# 10  
Old 06-30-2008
Hi.

These are often found in Linux systems, but you may be able to find them available on other systems (but I didn't see them on my Solaris system):
Code:
#!/bin/bash -

# @(#) s1       Demonstrate word differences.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) wdiff docdiff lynx
echo

echo " Input file data1:"
cat data1

echo
echo " Input file data2:"
cat data2

echo
echo " Results with wdiff:"
wdiff -n -3 -w "" -x "" -y "" -z "" data1 data2 > t1
lynx -force-html -dump t1

echo
echo " Results with docdiff:"
docdiff --digest --word data1 data2 > t1
lynx -force-html -dump t1

exit 0

Producing:
Code:
% ./s3

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
GNU wdiff 0.5
0.3.2
Lynx Version 2.8.5rel.1 (04 Feb 2004)

 Input file data1:
My name is x
Now is the time
Ernie went for a walk in the garden

 Input file data2:
My name is y
Now in the time
Cookie left his house for a walk along the garden path

 Results with wdiff:

   ======================================================================
   x y
   ======================================================================
   is in
   ======================================================================
   Ernie went Cookie left his house
   ======================================================================
   in along
   ======================================================================
   path
   ======================================================================

 Results with docdiff:

       _____________________________________________________________

     * 1,1

     My name is [DEL: x :DEL] [INS: y :INS]
     Now
         _____________________________________________________________

     * 2,2

     Now [DEL: is :DEL] [INS: in :INS] the time
         _____________________________________________________________

     * 3,3

     the time
     [DEL: Ernie went :DEL] [INS: Cookie left his house :INS] for a walk
         _____________________________________________________________

     * 3,3

     for a walk [DEL: in :DEL] [INS: along :INS] the
         _____________________________________________________________

     * 3,3

     the [DEL: garden :DEL] [INS: garden path :INS]
         _____________________________________________________________

Shell scripting alone is unlikely to satisfy any requirement that has to do with processing individual lines in large files. If you don't have or don't like wdiff or docdiff, then I think you'll need to continue searching, or write something in awk or perl ... cheers, drl
# 11  
Old 06-30-2008
FileKruncher

There are so many ways to skin this cat, but my favorite is the stl. If you use two custom streams, and tweak your buffers to the rightt size, you can do just about any kind of file comparison you can imagine, and get pretty good speed out of it.
I have a sample if you're interested. Here's an example of the streams (not completely tested).

WebKruncher.com/speedstreams.h - It's used like any typical file streams, just create and call getline 'till eof or read in chunks for a binary comparisons.
-Jmt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete file2.txt from file1.txt using scripting

Hi, I`m a total newbie, well my requirement is that i have 2 files I want to identify which countries i do not currently have in db.. how can i use the grep or another command to find this file .. i want to match all-countries.txt with countries-in-db.txt so the output is equal to... (11 Replies)
Discussion started by: beanbaby
11 Replies

2. Shell Programming and Scripting

Comparing two .txt files

i am working on a shell script and need help in the comparing part of it. for e.g. there two text files like this: file1.txt Code: name1 name2 name3 file1 has to be comared with file2 defaultfile.txt Code: name1 name2 (16 Replies)
Discussion started by: draghun9
16 Replies

3. Shell Programming and Scripting

Comparing 2 files using shell script

Hi Experts, I have 2 files 1 file consists of 800 records and 2 file consists of 100 records with matching column as Membership_Num.So i need a script which will compare the 2 files and displays the output.As these are the files the script should take any delimter like (tab,comma) as input... (6 Replies)
Discussion started by: naveen.dasu
6 Replies

4. UNIX for Dummies Questions & Answers

Comparing two txt files with AWK

Hi, I need to compare two text files with awk. File1: ------- chr1 43815007 43815009 COSM19193 REF=TG;OBS=AA;ANCHOR=G AMPL495041 chr1 43815008 43815009 COSM18918 REF=G;OBS=T;ANCHOR=T AMPL495041 chr1 115256527 115256528 ... (6 Replies)
Discussion started by: RushiK
6 Replies

5. Shell Programming and Scripting

comparing 2 files in shell script

I have 2 files config1h.txt ----------------- BFMU=ENABLE,ID=PM THR=OFF,REP=ALL,CON=IACM,TIM=OFF;GPON collection strategy 1.3.6.1.2.1.2.2:8 1.3.6.1.2.1.2.2:7 1.3.6.1.4.1.637.61.1.35.11.4:4 1.3.6.1.4.1.637.61.1.35.11.4:3 1.3.6.1.4.1.637.61.1.35.10.1:2 1.3.6.1.4.1.637.61.1.35.10.1:43... (7 Replies)
Discussion started by: LavanyaP
7 Replies

6. Shell Programming and Scripting

Comparing Strings in 2 .csv/txt files?

EDIT: My problems have been solved thanks to the help of bartus11 and pravin27 This code is just to help me learn. It serves no purpose other than that. Here's a sample csv that I'm working with - #listofpeeps.csv Jackie Chan,1954,M Chuck Norris,1930,M Bruce Lee,1940,M This code is... (13 Replies)
Discussion started by: chickeneaterguy
13 Replies

7. UNIX for Dummies Questions & Answers

How to cut data block from .txt file in shell scripting

Hi All, Currently i have to write a script. For which i need to cut a block from .txt file. I know the specific word that starts the block and ends the block. Can we do it in shell scripting..? Please suggest.... (6 Replies)
Discussion started by: pank29
6 Replies

8. Shell Programming and Scripting

comparing 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 and the files... (2 Replies)
Discussion started by: revenna
2 Replies

9. UNIX for Dummies Questions & Answers

shell script for comparing 2 files

Hi, how to read the 2 files and compare each other in shell script? i have 2 files test1 and test2, both files contains 20 character records.we have to compare file 1 records with file2, if exists then reject the record else we have to append it to test2 file. in file test1 around 100 single... (2 Replies)
Discussion started by: prashanth.spl
2 Replies

10. Shell Programming and Scripting

Comparing two txt files - pls help

Hi, I have some text files. I need a separate shell say 1.sh in which i can open a particular text file and compare with another txt file. For example: 1.log.txt contains apple ball cat goat 2.log.txt contains goat cat lion apple fox In my i.sh i need to write script to... (5 Replies)
Discussion started by: jisha
5 Replies
Login or Register to Ask a Question