02-27-2014
**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
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
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
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
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
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
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
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
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
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
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
CSREQ(1) BSD General Commands Manual CSREQ(1)
NAME
csreq -- Expert tool for manipulating Code Signing Requirement data
SYNOPSIS
csreq [-v] -r requirement-input -t
csreq [-v] -r requirement-input -b outputfile
DESCRIPTION
The csreq command manipulates Code Signing Requirement data. It reads one requirement from a file or command arguments, converts it into
internal form, checks it, and then optionally outputs it in a different form.
The options are as follows:
-b path
Requests that the requirement read be written in binary form to the path given.
-r requirement-input
Specifies the input requirement. See "specifying requirements" below. This is exactly the same format as is accepted by the -r and -R
options of the codesign(1) command.
-t Requests that the requirement read be written as text to standard output.
-v Increases the verbosity of output. Multiple instances of -v produce increasing levels of commentary output.
In the first synopsis form, csreq reads a Code Requirement and writes it to standard output as canonical source text. Note that with text
input, this actually compiles the requirement into internal form and then converts it back to text, giving you the system's view of the
requirement code.
In the second synopsis form, csreq reads a Code Requirement and writes its binary representation to a file. This is the same form produced by
the SecRequirementCopyData API, and is readily acceptable as input to Code Signing verification APIs. It can also be used as input to subse-
quent invocations of csreq by passing the filename to the -r option.
SPECIFYING REQUIREMENTS
The requirement argument (-r) can be given in various forms. A plain text argument is taken to be a path to a file containing the require-
ment. This program will accept both binary files containing properly compiled requirements code, and source files that are automatically com-
piled for use. An argument of "-" requests that the requirement(s) are read from standard input. Again, standard input can contain either
binary form or text. Finally, an argument that begins with an equal sign "=" is taken as a literal requirements source text, and is compiled
accordingly for use.
EXAMPLES
To compile an explicit requirement program and write its binary form to file "output":
csreq -r="identifier com.foo.test" -b output.csreq
To display the requirement program embedded at offset 1234 of file "foo":
tail -b 1234 foo | csreq -r- -t
FILES
DIAGNOSTICS
The csreq program exits 0 on success or 1 on failure. Errors in arguments yield exit code 2.
SEE ALSO
codesign(1)
HISTORY
The csreq command first appeared in Mac OS 10.5.0 .
BSD
June 1, 2006 BSD