Sponsored Content
Top Forums Shell Programming and Scripting **URGENT ** : Comparing the pattern of the file names in 2 different directories Post 302890488 by shadow_fawkes on Thursday 27th of February 2014 04:38:40 AM
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.
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
RMF(1)								     [nmh-1.5]								    RMF(1)

NAME
rmf - remove an nmh folder SYNOPSIS
rmf [+folder] [-interactive | -nointeractive] [-version] [-help] DESCRIPTION
Rmf removes all of the messages (files) within the specified (or default) folder, and then removes the folder (directory) itself. If there are any files within the folder which are not a part of nmh, they will not be removed, and an error will be produced. If the folder is given explicitly or the -nointeractive option is given, then the folder will be removed without confirmation. Otherwise, the user will be asked for confirmation. If rmf can't find the current folder, for some reason, the folder to be removed defaults to `+inbox' (unless overridden by user's profile entry "Inbox") with confirmation. If the folder being removed is a subfolder, the parent folder will become the new current folder, and rmf will produce a message telling the user this has happened. This provides an easy mechanism for selecting a set of messages, operating on the list, then removing the list and returning to the current folder from which the list was extracted. If rmf s used on a read-only folder, it will delete all the (private) sequences (i.e., "atr-seq-folder" entries) for this folder from your context without affecting the folder itself. Rmf irreversibly deletes messages that don't have other links, so use it with caution. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder Inbox: To find the default inbox SEE ALSO
rmm(1) DEFAULTS
`+folder' defaults to the current folder, usually with confirmation `-interactive' if +folder' not given, `-nointeractive' otherwise CONTEXT
Rmf will set the current folder to the parent folder if a subfolder is removed; or if the current folder is removed, it will make "inbox" current. Otherwise, it doesn't change the current folder or message. BUGS
Although intuitively one would suspect that rmf works recursively, it does not. Hence if you have a sub-folder within a folder, in order to rmf the parent, you must first rmf each of the children. MH.6.8 11 June 2012 RMF(1)
All times are GMT -4. The time now is 06:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy