How to compare the difference between a file and a folder??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to compare the difference between a file and a folder??
# 1  
Old 03-22-2007
How to compare the difference between a file and a folder??

Hi,

I have a .txt file which has to be compared with a folder and print the difference to some other .txt file.

I did try with the diff command..i mean

diff /tmp/aaa/bbb.txt /space/aaa/bbb/

/***bbb.txt contains all the files names which may or may not exist in the folder bbb..so i need to capture the files that does not in the folder***/

it gives me an error mesg saying..

diff : /space/aaa/bbb/ /bbb.txt : No such file or directory.

Can you help me out with some other command?

Thanks,
Kumar
# 2  
Old 03-22-2007
Quote:
Originally Posted by kumarsaravana_s
Hi,

I have a .txt file which has to be compared with a folder and print the difference to some other .txt file.

I did try with the diff command..i mean

diff /tmp/aaa/bbb.txt /space/aaa/bbb/

/***bbb.txt contains all the files names which may or may not exist in the folder bbb..so i need to capture the files that does not in the folder***/

it gives me an error mesg saying..

diff : /space/aaa/bbb/ /bbb.txt : No such file or directory.

Can you help me out with some other command?

Thanks,
Kumar
The man pages of diff says

Code:
SYNOPSIS
       diff [options] from-file to-file

       If from-file is a directory and to-file is not, diff compares the file
       in  from-file whose file name is that of to-file, and vice versa.  The
       non-directory file must not be -.

You may want to use something like this..

Code:
#! /bin/ksh

while read file
do
  [ ! -f "/space/aaa/bbb/${file}" ] && echo "${file} not present in /space/aaa/bbb"
done < /tmp/aaa/bbb.txt

Assuming bbb.txt contains a single filename per line.
# 3  
Old 03-22-2007
The best bet would be somthing like this...

Quote:
ls firstdir >a.txt
ls seconddir >b.txt
comm -23 a.txt b.txt >result.txt
Thnx.Dennis
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

2. Shell Programming and Scripting

How do you compare two folders and copy the difference to a third folder in a remote server?

How do you compare one local folder and a remote folder and copy the difference to a third folder in a remote folder.e.g. Folder A -- Is in a remote server and it has the following files TEST1.OUT TEST2.OUT TEST3.OUT Folder B --Is in a local server and it has the following files ... (5 Replies)
Discussion started by: cumeh1624
5 Replies

3. Shell Programming and Scripting

Compare files in a folder based on another file

I have a file named file.txt that looks as follows //class1.txt 45 234 67 89 90 //class2.txt 456 34 78 89 120 class1 and class2.txt are the names of files in a folder named folder1. The content of class1.txt file in folder1 67 9 89 5 234 9The content of class2.txt file in... (1 Reply)
Discussion started by: jaff rufus
1 Replies

4. Shell Programming and Scripting

Compare text file and a folder

Hi, I have a folder which contains some files a1.txt a2.txt a3.txt a4.txt a5.txt a6.txt a7.txt a8.txt a_index.txt Also i have a text file which contains entries like this a1.txt a3.txt a7.txt I want to comapare this text file and folder and remove the similar values in... (12 Replies)
Discussion started by: arijitsaha
12 Replies

5. Shell Programming and Scripting

Compare filename to file folder

Hi. I have a problem, could you help me ? Situation: there are alot of files in directory_1, with the names like "notneeded1blabla.bla", "notveryneededblabla.gla". there is directory_2 that has directories with names like that: "bla_needed1", "blab_veryneeded". What i need so much is to place... (7 Replies)
Discussion started by: sw_and
7 Replies

6. Shell Programming and Scripting

Compare large file and identify difference in separate file

I have a very large system generated file containing around 500K rows size 100MB like following HOME|ALICE STREET|3||NEW LISTING HOME|NEWPORT STREET|1||NEW LISTING HOME|KING STREET|5||NEW LISTING HOME|WINSOME AVENUE|4||MODIFICATION CAR|TOYOTA|4||NEW LISTING CAR|FORD|4||NEW... (9 Replies)
Discussion started by: jubaier
9 Replies

7. UNIX for Dummies Questions & Answers

Help with folder and file difference

Hello, I was wondering how to make difference between file and folder while using ls -l? I see it on the output because "d" is for dir and "-" for file, but how to make this input to other command? Because I am trying to bzip2 if it's the file and tar if it's a directory. (9 Replies)
Discussion started by: juzt1s
9 Replies

8. Shell Programming and Scripting

Compare selected columns from a file and print difference

I have learned file comparison from my previous post here. Then, it is comparing the whole line. Now, i have a new problem. I have two files with 3 columns separated with a "|". What i want to do is to compare the second and third column of file 1, and the second and third column of file 2. And... (4 Replies)
Discussion started by: kingpeejay
4 Replies

9. Shell Programming and Scripting

compare 2 file and print difference in the third file URG PLS

Hi I have two files in unix. I need to compare two files and print the differed lines in other file Eg file1 1111 2222 3333 file2 1111 2222 3333 4444 5555 newfile 4444 5555 Thanks In advance (3 Replies)
Discussion started by: evvander
3 Replies

10. Shell Programming and Scripting

compare two .dat files and if there is any difference pulled into a separate file

Hi, compare two .dat files and difference will be moved into separate file.if anybody having code for this please send asap. using diff command, i don't know how to write shell programming. and my first file is like this including Header and trailer 10Ç20060323Ç01(Header) 01ÇIÇbabuÇ3000 01ÇIÇbaluÇ4000... (1 Reply)
Discussion started by: kirankumar
1 Replies
Login or Register to Ask a Question