Sponsored Content
Top Forums Shell Programming and Scripting Match files between two folders Post 302921869 by alex2005 on Monday 20th of October 2014 03:59:36 PM
Old 10-20-2014
Match files between two folders

I have two folders:

FOLDER1
Code:
file_101_1010.txt
file_102_1007.txt
file_103_1003.txt
file_104_1007.txt
file_105_1011.txt
file_106_1006.txt
file_108_1007.txt
file_109_1002.txt
file_110_1006.txt
file_111_1008.txt
file_112_1011.txt
file_113_1012.txt
file_114_1001.txt
file_115_1009.txt
file_116_1002.txt
file_117_1003.txt
file_118_1006.txt
file_119_1012.txt
file_120_1010.txt
file_201_1003.txt
file_202_1004.txt
file_203_1007.txt
file_204_1002.txt
file_205_1010.txt
file_206_1005.txt
file_207_1006.txt
file_208_1006.txt
file_209_1001.txt
file_210_1004.txt
file_211_1003.txt
file_213_1008.txt
file_214_1001.txt
file_215_1004.txt
file_216_1001.txt
file_217_1003.txt
file_218_1005.txt
file_219_1006.txt
file_220_1012.txt
file_301_1010.txt
file_302_1007.txt
file_303_1008.txt
file_304_1011.txt
file_306_1006.txt
file_307_1008.txt
file_308_1009.txt
file_309_1009.txt
file_310_1009.txt
file_311_1012.txt
file_312_1006.txt
file_313_1010.txt
file_314_1005.txt
file_315_1003.txt
file_316_1010.txt
file_318_1002.txt
file_319_1010.txt
file_320_1001.txt

FOLDER2
Code:
myfile_1007_102.log
myfile_1003_103.log
myfile_1011_105.log
myfile_1006_106.log
myfile_1002_107.log
myfile_1007_108.log
myfile_1008_111.log
myfile_1011_112.log
myfile_1012_113.log
myfile_1001_114.log
myfile_1009_115.log
myfile_1002_116.log
myfile_1003_117.log
myfile_1006_118.log
myfile_1012_119.log
myfile_1010_120.log
myfile_1003_201.log
myfile_1004_202.log
myfile_1007_203.log
myfile_1002_204.log
myfile_1010_205.log
myfile_1005_206.log
myfile_1006_207.log
myfile_1006_208.log
myfile_1001_209.log
myfile_1004_210.log
myfile_1003_211.log
myfile_1002_212.log
myfile_1008_213.log
myfile_1001_214.log
myfile_1004_215.log
myfile_1001_216.log
myfile_1003_217.log
myfile_1006_219.log
myfile_1012_220.log
myfile_1010_301.log
myfile_1007_302.log
myfile_1008_303.log
myfile_1011_304.log
myfile_1003_305.log
myfile_1006_306.log
myfile_1008_307.log
myfile_1009_308.log
myfile_1009_309.log
myfile_1009_310.log
myfile_1012_311.log
myfile_1006_312.log
myfile_1010_313.log
myfile_1005_314.log
myfile_1010_316.log
myfile_1001_317.log
myfile_1002_318.log
myfile_1010_319.log
myfile_1001_320.log

The naming convention for the files are:

Code:
FOLDER1/file_ID_VALUE.txt  
FOLDER2/myfile_VALUE_ID.log

I'm trying to list all the ID values in sequence (101-120, 201-220, 301-320), match file ID's between the 2 folders and print VALUE :

Code:
ID   - VALUE-FOLDER1 VALUE-FOLDER2
101  -  1010    1010
102  -  1007    1007
103  -  1003    1003
104  -  1007        
105  -  1011    1011
106  -  1006    1006
107  -          1002
108  -  1007    1007
109  -  1002        
110  -  1006        
111  -  1008    1008
112  -  1011    1011
113  -  1012    1012
114  -  1001    1001
115  -  1009    1009
116  -  1002    1002
117  -  1003    1003
118  -  1006    1006
119  -  1012    1012
120  -  1010    1010
201  -  1003    1003
202  -  1004    1004
203  -  1007    1007
204  -  1002    1002
205  -  1010    1010
206  -  1005    1005
207  -  1006    1006
208  -  1006    1006
209  -  1001    1001
210  -  1004    1004
211  -  1003    1003
212  -          1002
213  -  1008    1008
214  -  1001    1001
215  -  1004    1004
216  -  1001    1001
217  -  1003    1003
218  -  1005        
219  -  1006    1006
220  -  1012    1012
301  -  1010    1010
302  -  1007    1007
303  -  1008    1008
304  -  1011    1011
305  -          1003
306  -  1006    1006
307  -  1008    1008
308  -  1009    1009
309  -  1009    1009
310  -  1009    1009
311  -  1012    1012
312  -  1006    1006
313  -  1010    1010
314  -  1005    1005
315  -  1003        
316  -  1010    1010
317  -          1001
318  -  1002    1002
319  -  1010    1010
320  -  1001    1001

Here is what I did so far (script run in FODLER1):

Code:
#!/bin/gawk -f

BEGIN { 
{
print "ID   -","VALUE-FOLDER1", "VALUE-FOLDER2"
}
}	
ENDFILE{
id1[substr(FILENAME,3,3)]=substr(FILENAME,10,4)
for (i=101; i<=320; i++) 
{
if (i%100 <=20 && i%100 > 0) 
{
if ( i in id1)
{
print i," - ",id1[i]
}
}
}
}

Could you please help me for resolving this matter?

Thanks in advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

removing old files except configuration files and folders

Dear all, I want to remove files older than 2 months in the /home/member directory. But except the configuration files (like .bash_profile .config/ .openoffice/ .local/ .kde/ etc..) I have tried with the command find . -mtime +60 -wholename './.*' -prune -o -print -exec mv {} \; but it... (1 Reply)
Discussion started by: jamcalicut
1 Replies

2. HP-UX

to get the timestamp of files from the files and folders in Unix

Hi, I had a directory and many subdirectories and files with in it. Now i want to get the timestamp of files from the files and folders recursively. :( Please help me to generate a script fort he above mentioned requirement! Appreciate for ur qick response Thanks in advance! ... (2 Replies)
Discussion started by: kishan
2 Replies

3. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

Hi, all: I've got two folders, say, "folder1" and "folder2". Under each, there are thousands of files. It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command. However, if I change the above question a... (1 Reply)
Discussion started by: jiapei100
1 Replies

4. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

5. Shell Programming and Scripting

List all the files in the present path and Folders and subfolders files also

Hi, I need a script/command to list out all the files in current path and also the files in folder and subfolders. Ex: My files are like below $ ls -lrt total 8 -rw-r--r-- 1 abc users 419 May 25 10:27 abcd.xml drwxr-xr-x 3 abc users 4096 May 25 10:28 TEST $ Under TEST, there are... (2 Replies)
Discussion started by: divya bandipotu
2 Replies

6. UNIX for Dummies Questions & Answers

Listing folders and files within

is there any command that can make listing files like this /data/seismic/prestack-4/eon5/PEP/JAWA/AKASIA-BAGUS/3D/F/BL3-4/F12AKB3D_SW82-128_ID1696-1850.segy /data/seismic/prestack-4/eon5/PEP/JAWA/AKASIA-BAGUS/3D/F/BL3-4/F12AKB3D_SW82-128_ID1851-1975.segy ... (2 Replies)
Discussion started by: muhnandap
2 Replies

7. Shell Programming and Scripting

New files based off match or no match

Trying to match $2 in original_targets with $2 of new_targets . If the two numbers match exactly then a match.txt file is outputted using the information in the new_targets in the beginning 4 fields $1, $2, $3, $4 and value of $4 in the original_targets . If there is "No Match" then a no... (2 Replies)
Discussion started by: cmccabe
2 Replies

8. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

10. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies
All times are GMT -4. The time now is 09:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy