Sponsored Content
Top Forums Shell Programming and Scripting Compare contents of two files Post 302528220 by newpromo on Monday 6th of June 2011 04:43:27 PM
Old 06-06-2011
Compare contents of two files

Hello,

I have two files containing both two columns:

Code:
$ cat file1
col1 nbr1
col2 nbr2
col3 nbr3
...

Code:
$ cat file2
val1 ri1
val2 ri2
val3 ri3

...

I need to compare every nbr (nbr1, nbr2,...) in the second column of file1 with every ri (ri1, ri2,...) in the second column of file2. And when nbr=ri ===> write in the output file : [(val - col) nbr]

The output file shoud look like :

Code:
$ cat file3
(val1 - col1) nbr1    (if nbr1=ri1)
(val3 - col3) nbr3    (if nbr3=ri3)

Thank you,
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 06-06-2011 at 05:45 PM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

compare array contents with file

I have an array "arrA" with the following contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf My data file "Files.dat" has the same contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf I have a script that compares... (0 Replies)
Discussion started by: orahi001
0 Replies

2. Shell Programming and Scripting

Compare & replace contents within a file

I have 2 files file1 1 TMQUEUE QUE1 STMW633A 100 DMADM DOMGRPSTMW633A STMW633A 100 GWADM GWTGRPSTMW633A STMW633A 100 GWADM GWTGRPSTMW633AA STMW633A 100 GWADM GWTGRPSTMW638A STMW638A 100 TMSYSEVT EVTGRPSTMW633A STMW633A 100 TMSYSEVT ... (2 Replies)
Discussion started by: kaustubh137
2 Replies

3. Shell Programming and Scripting

How to compare contents of two CSV rows

I have been trying to find the answer to this but can't seem to get it. I have two rows, both are CSV files. I want to iteratively compare each field value to the corresponding value in the second file. Example: File 1.txt 1|hello|3.2|AMB||||B File 2.txt 1|hi|3,2|ABC||||C The... (1 Reply)
Discussion started by: axwack
1 Replies

4. Shell Programming and Scripting

Compare two files and remove all the contents of one file from another

Hi, I have two files, in which the second file has exactly the same contents of the first file with some additional records. Now, if I want to remove those matching lines from file2 and print only the extra contents which the first file does not have, I could use the below unsophisticated... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. Shell Programming and Scripting

compare the contents of two directories

i have been asked to write a bash shell script comparing two directories and sed or awk should not be used in this assignment. compdir will compare filenames in two directories, and list information about filenames that are in one directory but not the other. The information listed will be a long... (1 Reply)
Discussion started by: soccerball
1 Replies

6. Shell Programming and Scripting

Compare folder contents over network

I use diff -r dir1 dir2 to get comparison of two folders that are on same machine. Now I need the same thing but one of the folders is on a different machine. Currently I ftp the folder to a temp folder compare using above command and delete the temp folder. Is there any other better options?... (5 Replies)
Discussion started by: ke3kelly
5 Replies

7. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

8. Shell Programming and Scripting

shell script to compare file contents

Hello Has anyone got an example shell script that I can use to compare the contents of two files. The files should contain the same contents, eg. file1.txt apple pear grape file2.txt apple pear grape (2 Replies)
Discussion started by: deedaz
2 Replies

9. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

10. Shell Programming and Scripting

How to compare two file contents which created within one hour?

Hi Gurus, I need to compare two file contents and log the difference. the detail as below: in current directory there is file abc20140728_1020.txt abc20140728_1110.txt I need to find the files which created within 60 minutes first then compare the contents. I am able to use find... (12 Replies)
Discussion started by: ken6503
12 Replies
ZDIFF(1)                                                      General Commands Manual                                                     ZDIFF(1)

NAME
zcmp, zdiff - compare compressed files SYNOPSIS
zcmp [ cmp_options ] file1 [ file2 ] zdiff [ diff_options ] file1 [ file2 ] DESCRIPTION
Zcmp and zdiff are used to invoke the cmp or the diff program on files compressed via gzip. All options specified are passed directly to cmp or diff. If only file1 is specified, it is compared to the uncompressed contents of file1.gz. If two files are specified, their con- tents (uncompressed if necessary) are fed to cmp or diff. The input files are not modified. The exit status from cmp or diff is pre- served. SEE ALSO
cmp(1), diff(1), zmore(1), zgrep(1), znew(1), zforce(1), gzip(1), gzexe(1) BUGS
Messages from the cmp or diff programs may refer to file names such as "-" instead of to the file names specified. ZDIFF(1)
All times are GMT -4. The time now is 01:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy