I am trying to compare the contents of 4 directories using diff, where I want files that are present in dir1 but not in dir2, dir3 or dir4 I know this command can only compare 2 files, but I was hoping to find a way to get around this.
I have this thought on my mind
The command in non-functional, I am just expressing the idea of performing diff many times on the resulting files, can this be done in Linux?
This might sound a little retarded, any better ideas are welcomed, my target is just to find the unique files in a certain directory.
It might help if you could clarify which files exactly you are searching for. If, for instance, a file exists in dir1 and dir2, but not in dir3 and dir4, should it be included or not? How about a file existing in dir1, dir2, dir3 but not in dir4? Does "dir1" take any precendence or should a file existing in dir1 and dir2 but not in dir3 and dir4 be treated the same as one existing in dir2 and dir4 but not in dir1 and dir3?
In other words, could you clarify the rules by which you want to find files? A possible solution (maybe not even relying on "diff") wil depend on how you answer these questions.
Hello bakunin, I am actually looking to do all the possible combinations for these 4 directories, starting with the most simple, a file that exists in dir1, but not in any other directory.
Afterwards, I want to start doing combinations, like available in dir1 and dir3 but not in dir2 and dir4. This sounds like a very basic command to me but, I wasn't able to come up with the right formula to do this.
When I thought you always wanted to work on three directories, I started working on the following script:
which produces the output:
for the directory hierarchy given in the 1st message in this thread when it is saved in a file named tester and invoked as:
Note that it was written using the Korn shell, but it uses an extension not specified by the standards (${var:start:length} to get a substring from a variable). This is at least available in recent versions of bash and ksh versions more recent that November 16, 1988.
Your specification of the output you wanted is very vague, so this might not even be close to what you want; but I hope it will give you some idea of how to approach your problem.
If you want us to pursue your new, more general problem with an unlimited number of directories and unspecified combinations of comparisons, you need to give a much more detailed description of what you want to happen, how you want to specify the options and operands for this command, and how you want the output formatted. Try to write a man page describing the utility you want to create.
This User Gave Thanks to Don Cragun For This Post:
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Quote:
Originally Posted by Error404
...Afterwards, I want to start doing combinations, like available in dir1 and dir3 but not in dir2 and dir4. This sounds like a very basic command to me but, I wasn't able to come up with the right formula to do this.
You may be interested in combine:
This is one utility in a package, moreutils, available in some distributions (Debian is where I obtained i)t. It is also maintained at moreutils
Guys i have 3 files,
but i want to compare and diff only the 2nd column
path=`/home/whois/doms`
for i in `cat domain.tx`
do
whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant
whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Hi,
Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl.
../ORCL_data01/oradata/orcl/data.
../ORCL_data01/oradata/orcl/redo.
Script :-
=========
for dir in `ls -d... (8 Replies)
Hi,
I'd like to process multiple files. For example:
file1.txt
file2.txt
file3.txt
Each file contains several lines of data. I want to extract a piece of data and output it to a new file.
file1.txt ----> newfile1.txt
file2.txt ----> newfile2.txt
file3.txt ----> newfile3.txt
Here is... (3 Replies)
Hi All,
I have two files which look as below
File1
serial="1" name="abc" type="employee" field="IT"
serial="2" name="cde" type="intern" field="Marketing"
serial="3" name="pqr" type="contractor" field="IT"
serial="4" name="xyz" type="employee" field="Sales"
File2
serial="1"... (3 Replies)
Hi,
I have 2 files.I want to check if file1 is contained in file2.
A.txt:
-----
AAA
BBB
B.txt:
------
CCC
AAA
BBB
DDD
I want to check if A.txt is contained in B.txt. Can it be done using SED ? (12 Replies)
Okay, not sure if it can be done, I would think it could be done and I'm just having a hard time with it.
fun_close_wait(){
ipVar="${1} ${2}"
portVar=`cat "${5}" | cut -d' ' -f 1`
for ip in $ipVar
do
for port in $portVar
do
netstatVar=`netstat -n | grep... (4 Replies)
Hi Masters,
I have two files named file1 and file2.
Both the files contains the same contents with some difference in comments,space.But no content change.
I tried to find the diff between the two files to make sure that contents are same.
For that i tried
diff -ibw file1 file2
But... (1 Reply)
I need to compare 2 diff type of files and find out the duplicate after comparing each types of files:
Type 1 file name is like: file1.abc
(the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations).
The other file is file1.bcd01abc (the extension... (2 Replies)
At the office, we often have to edit one file with VI. We are 4-6 workers doing it and sometimes can be done at the same time.
We have found a problem and want to prevent it with a file lock. Is it possible and how ?
problem :
Worker-a starts edit VI session on File-A at 1PM
Worker-b... (14 Replies)
Hello,
I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3.
For example:
file 1
123
1234
123456
file 2
123
2345
23456
file 3 should have
2345
23456
I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)