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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting **URGENT ** : Comparing the pattern of the file names in 2 different directories
# 1  
Old 02-27-2014
Error **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 TGT_DIR1 & TGT_DIR2 are same but folder name is TGT_DIR1 & TGT_DIR2)

Say the files in folder SRC_DIR1 is as fololws :
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 :
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)

Can any body say how to approach this using PERL SCRIPT. Since I am from DWH background and have not worked on PERL Script any help is highly required.
# 2  
Old 02-27-2014
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
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. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: shadow_fawkes
4 Replies

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. Shell Programming and Scripting

[Urgent]how to print the file names into a txt file???

HI, I have a folder with some 120 files...i just want to print all the file filenames(not the content or anything else) onto a file say .txt. please help me with this command Thanks a lot. (15 Replies)
Discussion started by: kumarsaravana_s
15 Replies
Login or Register to Ask a Question