Comparing the pattern of the file names in 2 different directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing the pattern of the file names in 2 different directories
# 1  
Old 02-27-2014
Comparing the pattern of the file names in 2 different directories

Hi,

I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement.

There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2
(Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of TGT_DIR1 & TGT_DIR2 are same but folder name is TGT_DIR1 & TGT_DIR2)

Say the files in folder SRC_DIR1 is as fololws :
Code:
aab_TRADE_20130226110444.csv
i.aab_20130226110444.csv
price.aab_20130226110444.csv
aab.i_20130226110444.csv
aab_price_aab_20130226110444.csv

Say the files in folder SRC_DIR2 is as follows :
Code:
aab_TRADE_20130226110444_PROCESSED.csv
i.aab_20130226110444_PROCESSED.csv
price.aab_20130226110444_PROCESSED.csv
aab.i_20130226110444_PROCESSED.csv
aab_price_aab_20130226110444_PROCESSED.csv

Now, each file present in folder SRC_DIR1 is compared with the folder SRC_DIR2 based on the following conditions :
CONDITION 1:
If any files in folder SRC_DIR1 whose first 20 characters is same as those in SRC_DIR2 and those 20 characters have has something like 'trade' as part of the filename then those files are to taken from SRC_DIR1 and moved to TGT_DIR1 and files in SRC_DIR2 to be moved to TGT_DIR2
OR
CONDITION 2:
If any files in folder SRC_DIR1 whose first 20 characters match with those in SRC_DIR2 and first 2 character of those 20 characters have the filename something like 'i.' as part of the filename then those files are to taken from SRC_DIR1 and moved to TGT_DIR1 and files in SRC_DIR2 to be moved to TGT_DIR2.
OR
CONDITION 3
If any files in folder SRC_DIR1 whose first 20 characters match with those in SRC_DIR2 and first 6 character of those 20 characters have the filename something like 'price.' as part of the filename then those files are to taken from SRC_DIR1 and moved to TGT_DIR1 and files in SRC_DIR2 to be moved to TGT_DIR2.

Now, there will be files in folder TGT_DIR1 and TGT_DIR2.
Files which satisfy condition 1 :
Lastly after getting the files in TGT_DIR1, the file content (present after 2nd comma and before 3rd comma has to be extracted and append a string like 'ABC,' before the extracted value. The new file name given can be said as SOURCE_FILE.csv. File present in TGT_DIR2 need not to be altered.

Files which satisfy condition 2 :
Lastly after getting the files in TGT_DIR1, the file content (present after 4th comma and before 5th comma has to be extracted and append a string like 'XYZ,' before the extracted value. All this records satisfying the condition 2 file naming convention should be appended to the above file name said as SOURCE_FILE.csv.

Files which satisfy condition 3:
Lastly after getting the files in TGT_DIR1, the file content (present after 7th comma and before 8th comma has to be extracted and append a string like 'MNO,' before the extracted value. All this records satisfying the condition 3 file naming convention should be appended to the above file name said as SOURCE_FILE.csv.

Finally the SOURCE_FILE.csv isto be created into a new path whose folder name is say TGT_DIR (for path of TGT_DIR is not as same as TGT_DIR1 & TGT_DIR2)

Since, I am a DWH Architect and the specialist is gone for vocation, I had
to ask you guys for help. I do not DEMAND an answer but REQUEST your help if you can. If so, I don't have to reassign the ticket and making his vocation ruined.

Last edited by Franklin52; 02-27-2014 at 06:40 AM.. Reason: Please use code tags
# 2  
Old 02-27-2014
Hi shadow_fawkes,

1. Why does it have to be done in Perl?
2. Have you tried anything already? We can help you, but we can't build the whole script
3. As your previous post suggested it was urgent, you might be better of hiring a consultant on sites like oDesk to do the job quickly
# 3  
Old 02-27-2014
Hi,
Thanks for the reply.
Anyways I have assigned the ticket to the respective owners. If you can help how to get through this situation for anybody in future requiring such doubts. Kindly provide any solutions whichever you can.
Thanks for the reply.
# 4  
Old 02-27-2014
Hi shadow_fawkes, I don't know what you mean with "I have assigned the ticket to the respective owners". Does that mean you no longer want your question answered and that we should close your thread? If you still would like some help, it would be good if you could answer Subbeh's questions..
# 5  
Old 02-27-2014
Lightbulb

What I meant is, I am not from PERL team and since the responsible guy went for vocation, I thought of getting help from you guys for this requirement instead of him canceling the vocation. I thought, if any of you help me then I can put the code into live but it seems it requires more workmanship. Hence I have sent the job to himself, now he had to come half-way this travel to work on this fix.

And I intent to keep this forum open because, in future some or the other would require the same requirement and if answered, it will be useful for them to get the solutions from this forum thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing file names with different extensions

Hello, I need some help. I have files in one and the same directory, but with different extensions, like this: file1.IN file2.IN file3.IN file1.OUT file2.OUT Apparently some files with OUT extension can be missing. So I want to compare *.IN and *.OUT, ignoring the extension and get result... (3 Replies)
Discussion started by: apenkov
3 Replies

2. UNIX for Beginners Questions & Answers

Consternation of multiple file names based on naming pattern

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

3. Shell Programming and Scripting

**URGENT ** : Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (1 Reply)
Discussion started by: shadow_fawkes
1 Replies

4. Shell Programming and Scripting

Script for Comparing directories and file from a text file

Hello all, I need to write a script which has following requirement: Need to read the filenames from text file and then search for the above read files in the required directory and if match found backup them in a backup folder. And also need to compare and verify whether the files in the... (7 Replies)
Discussion started by: saurau
7 Replies

5. Shell Programming and Scripting

Comparing File Names

Hi All , I am new to UNIX. I have a requirement where user transfers 10-15 files into a directory "/upload". File name will be like T1234_H and T1234_D or R1234_H and R1234_D . The _H and _D files are associated to each other.They must always be together in the server. Once the files are... (2 Replies)
Discussion started by: Raviteja_B
2 Replies

6. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

7. Shell Programming and Scripting

How to find pattern in file names?

I have some files, those are abbreviated (ed,ea, and bi) company_ed_20100719.txt company_ea_20100719.txt company_bi_20100719.txt I would like to rename these files by replacing ed with EmployeeDetails ea with EmployeeAddress bi with BankInfomration as company_... (3 Replies)
Discussion started by: LinuxLearner
3 Replies

8. Shell Programming and Scripting

Remove repeating pattern from beginning of file names.

I want a shell script that will traverse a file system starting at specific path. And look at all file names for repeating sequences of and remove them from the file name. The portion of the name that gets removed has to be a repeating sequence of the same characters. So the script would... (3 Replies)
Discussion started by: z399y
3 Replies

9. UNIX for Dummies Questions & Answers

Comparing file names to text document

Hi All, I'm really new to Unix scripts and commands but i think i'm eventually getting the hang of some of it. I have a task which is to create some kind of script which compares the file names in a directory, with the associated file name in a .txt file. We send out some data and Unix has a... (1 Reply)
Discussion started by: gman
1 Replies

10. Shell Programming and Scripting

Compare File Names in Different Directories...

I do not know much about shell scripting and need to create a script and I am at a loss. If someone can help me, that would be great!! I have two directories: /dir1 /dir2 I need to get the sequence number which is part of the filename in /dir1 and delete all files in /dir2 that are... (4 Replies)
Discussion started by: stky13
4 Replies
Login or Register to Ask a Question