finding matches between multiple files from different directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding matches between multiple files from different directories
# 1  
Old 03-29-2012
finding matches between multiple files from different directories

Hi all...
Can somebody pls help me with this...
I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt).
I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir containing three text files(r1.txt,r2.txt,r3.txt).
Now i want to do something like this for all the subdirectories in dir1:
Code:
comm -12<(ls ~/dir1/sub1/ras.txt) <(ls ~/dir2/sub1c/r1.txt)
comm -12<(ls ~/dir1/sub1/ras.txt) <(ls ~/dir2/sub1c/r2.txt)
comm -12<(ls ~/dir1/sub1/ras.txt) <(ls ~/dir2/sub1c/r3.txt)

(i do not know if its right!!)
I have two questions:
1)How to find the matched lines in the two text files
2) How to pipe the corresponding output to a new file(eg. newr1.txt,newr2.txt,newr3.txt) for all the subdirectories in dir1.
NOTE: the names of the subdirectories in dir1 and dir2 are similar(eg: vr001 and vr001clusters)

Pls help me!!

Sample content of files:

ras.txt
Code:
#!rasmol -script
zap
load inline
select all
exit
HEADER    Model of O957                 
REMARK 220  SCORE:       0.92                          
REMARK 220 ZDOPE:                       -0.7                          
REMARK 220 EVALUE:                               0                    
REMARK 220 TEMPLATE PDB:                2g38                          
REMARK 220 TEMPLATE CHAIN:              B                             
REMARK 220 TARGET LENGTH:               409                           
ATOM      1  N   PHE     1       9.735  29.148  72.991  1.00 41.06       1SG   2
ATOM      2  CA  PHE     1      10.609  27.961  72.870  1.00 41.06       1SG   3
ATOM      3  CB  PHE     1       9.958  26.763  73.577  1.00 41.06       1SG   4
ATOM      4  CG  PHE     1       9.871  27.129  75.019  1.00 41.06       1SG   5
ATOM      5  CD1 PHE     1      10.985  27.086  75.826  1.00 41.06       1SG  6
ATOM      6  CD2 PHE     1       8.667  27.510  75.564  1.00 41.06       1SG   7
ATOM      7  CE1 PHE     1      10.893  27.426  77.157  1.00 41.06       1SG  8
ATOM      8  CE2 PHE     1       8.570  27.850  76.893  1.00 41.06       1SG   9
ATOM      9  CZ  PHE     1       9.687  27.810  77.693  1.00 41.06       1SG  10
ATOM     10  C   PHE     1      10.823  27.638  71.429  1.00 41.06       1SG 11

r1.txt


Code:
ATOM      1  N   PHE     1       9.735  29.148  72.991  1.00 41.06       1SG   2
ATOM      2  CA  PHE     1      10.609  27.961  72.870  1.00 41.06       1SG   3
ATOM      3  CB  PHE     1       9.958  26.763  73.577  1.00 41.06       1SG   4
ATOM      4  CG  PHE     1       9.871  27.129  75.019  1.00 41.06       1SG   5
ATOM      6  CD2 PHE     1       8.667  27.510  75.564  1.00 41.06       1SG   7
ATOM      8  CE2 PHE     1       8.570  27.850  76.893  1.00 41.06       1SG   9
ATOM      9  CZ  PHE     1       9.687  27.810  77.693  1.00 41.06       1SG  10
ATOM     10  C   PHE     1      10.823  27.638  71.429  1.00 41.06       1SG 11
ATOM     11  O   PHE     1      11.653  26.802  71.077  1.00 41.06       1SG 12
ATOM     14  C   GLY     2      11.511  28.683  68.741  1.00 34.54       1SG 15
ATOM     15  O   GLY     2      12.041  28.302  67.700  1.00 34.54       1SG 16
ATOM     16  N   ALA     3      12.083  29.612  69.526  1.00 22.67       1SG 17
ATOM     17  CA  ALA     3      13.389  30.104  69.204  1.00 22.67       1SG18
ATOM     20  O   ALA     3      15.218  28.819  68.407  1.00 22.67       1SG 21
ATOM     21  N   LEU     4      14.259  28.124  70.328  1.00 86.18       1SG 22


Moderator's Comments:
Mod Comment Please use code tags! Also please do not overly use font formattings, thanks. You also got a PM with an explanation.

Last edited by zaxxon; 03-29-2012 at 04:15 AM.. Reason: code tags, font formattings
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding files deep in directories

i need to find a portable way to go through multiple directories to find a file. I've trid something like this: find /opt/oracle/diag/*/alert_HH2.log -printordinarily, i can run the ls command and it will find it: /opt/oracle/diag/*/*/*/*/alert_HH2.log The problem with this approach is... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Finding non-existing words in a list of files in a directory and its sub-directories

Hi All, I have a list of words (these are actually a list of database table names separated by comma). Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories. Sample list of words:... (8 Replies)
Discussion started by: Bhanu Dhulipudi
8 Replies

3. Programming

Finding duplicate files in two base directories

Hello All, I have got some assignment to complete till this Monday and problem statement is as follow :- Problem :- Find duplicate files (especially .c and .cpp) from two project base directories with following requirement :- 1.Should be extendable to search in multiple base... (4 Replies)
Discussion started by: anand.shah
4 Replies

4. Shell Programming and Scripting

Compare 2 files and print matches and non-matches in separate files

Hi all, I have two files, chap.txt and complex.txt. chap.txt looks like this: a d l m r k complex.txt looks like this: a c d e l m n j a d l p q r c p r m ......... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Finding the Files In the Same Name Directories

Hi, In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those... (6 Replies)
Discussion started by: Siva Sankar
6 Replies

6. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

7. Shell Programming and Scripting

FTP multiple files from multiple directories

I have multiple files that starts as TRADE_LOG spread across multiple folders in the given structure.. ./dir1/1/TRADE_LOG*.gz ./dir2/10/TRADE_LOG*.gz ./dir11/12/TRADE_LOG*.gz ./dir12/13/TRADE_LOG*.gz when I do ftp uisng mput from the "." dir I am getting the below given error mput... (1 Reply)
Discussion started by: prasperl
1 Replies

8. UNIX for Dummies Questions & Answers

finding largest files (not directories)?

hello all. i would like to be able to find the names of all files on a remote machine using ssh. i only want the names of files, not directories so far i'm stuck at "du -a | sort -n" also, is it possible to write them to a file on my machine? i know how to write it to a file on that... (2 Replies)
Discussion started by: user19190989
2 Replies

9. Shell Programming and Scripting

Expression for Finding Multiple Directories..??

I am writing a shell script to search for previous versions of an application...the application is called TAU and basically i want to search the users home directory and /Applications for any instances of a "TAU" folder.. If found i want to give the user the option to remove the old folders and if... (3 Replies)
Discussion started by: meskue
3 Replies

10. UNIX for Dummies Questions & Answers

Finding executable files in all directories

This is probably very easy but I would like to know a way to list all my files in all my directories that are readable and executable to everyone. I was told to use find or ls and I tried some stuff but couldnt get it to work. I understand that its dangerous to have files with these permissions for... (4 Replies)
Discussion started by: CSGUY
4 Replies
Login or Register to Ask a Question