Visit Our UNIX and Linux User Community


Move multiple files 4rm Source to different target folders based on a series num in the file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move multiple files 4rm Source to different target folders based on a series num in the file content
# 1  
Old 11-25-2016
Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts

my scenario is as follows...

I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims".

All files are getting created in Source folder. I request for a unix script to open the file and check for its series (wheter its 123456 or 789101 series) number in its header and move the files to its corresponding Target folders "Target_123456" OR "Target_789101".

Please Note:
for DEBIT.DAT file the series number is available in line 1 i.e “VOL1000001 123456
for Claim & Refund files the series number is available in line 1 i.e “PWRD002123456 123456 00”

123456 Series files
DEBIT.DAT :-
Code:
VOL1000001                               123456                                1 
HDR1A123456S  112345600000100010001       16194 162000000000      
HDR2F0200000100                                   00

CLAIM.DAT:-
Code:
PWRD001123456               123456 00  
VOL1000001                               123456                                1
HDR1A123456S  112345600000100010001       16295 162960000000
HDR2F0200000100                                   00

REFUND.DAT:-
Code:
PWRD002123456               123456 00
VOL1000002                               123456                                1
HDR1A      S  112345600000200010001       16294 162960000000
HDR2F0200000100                                   00


789101 Series files
DEBIT.DAT:-
Code:
VOL1000001                               789101                                1
HDR1A789101S  178910100000100010001       16194 162000000000  
HDR2F0200000100                                   00

CLAIM.DAT:-
Code:
PWRD001789101               789101 00
VOL1000001                               789101                                1
HDR1A789101S  178910100000100010001       16295 162960000000
HDR2F0200000100                                   00

REFUND.DAT:-
Code:
PWRD002789101               789101 00
VOL1000002                               789101                                1
HDR1A      S  178910100000200010001       16294 162960000000
HDR2F0200000100                                   00


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
And - DON'T use those abundant COLOR and FONT tags!

Last edited by RudiC; 11-25-2016 at 05:57 PM.. Reason: Added CODE tags.
# 2  
Old 11-25-2016
Any attempts/ideas/thoughts from your side?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-25-2016
Hi

I am able to achieve this in Java. I am not comfortable in unix scripting. Tried searching for similar threads.
# 4  
Old 11-25-2016
What be the target file names? Duplicates won't be allowed, neither in source nor in target directories.
# 5  
Old 11-25-2016
Thanks a lot for your response.
Target file names should be same as source file names. duplicates should not be allowed.
# 6  
Old 11-25-2016
SO - latest if each set has been moved once, duplicates will occur with the next action. Which measures do you intend to take for these cases?
# 7  
Old 11-25-2016
I get files in source folder with unique names appended with ddmmyyyyhhmmss. e.g Debit25112016222930.dat

So no need to consider duplicate file scenario.

Previous Thread | Next Thread
Test Your Knowledge in Computers #939
Difficulty: Easy
The author named the ping utility after the sound that a sonar makes.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i move folders and its content if folder is older than 1,5 days and keep subdirs in bash?

Hello all, do you know any way i can i move folders and its content if folder is older than 1,5 days in bash? I tried: find /home/xyz/DATA/* -type d -ctime +1.5 -exec mv "{}" /home/xyz/move_data_here/ \;All i got was that Files from DATA /home/xyz/DATA/* ended messed up in... (1 Reply)
Discussion started by: ZerO13
1 Replies

2. Shell Programming and Scripting

Bash to move specific files from folders in find file

I have a directory /home/cmccabe/nfs/exportedReports that contains multiple folders in it. The find writes the name of each folder to out.txt. A new directory is then created in a new location /home/cmccabe/Desktop/NGS/API, named with the date. What I am trying to do, unsuccessfully at the moment,... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Script to move files in multiple folders

Hello all, I would appreciate any help to write a script. I have folder A which contains over 30 thousands xml files, I would like create multiple folders and move those files (500 in each folders). Thank you (1 Reply)
Discussion started by: mmsiddig
1 Replies

4. Solaris

Move files into different folders based on its month

Hi All, I want to move the files in to different folders based on the files month in the file timestamp. For example All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder... Please help me to achive the above... (10 Replies)
Discussion started by: velava
10 Replies

5. Shell Programming and Scripting

move set of files to the target path with different extension

I have the following files in the dir /home/krishna/datatemp abc.xml cde.xml asfd.txt asdf_20120101-1.xml asdf_20120101-2.xml asdf_20120101-3.xml asdf_20120101-4.xml Now I need to move the files having the pattern asdf_20120101-*.xml to the dir /home/krishna/dataout with the extn as... (1 Reply)
Discussion started by: kmanivan82
1 Replies

6. Shell Programming and Scripting

Archive files to different target folders based on criteria

Hi All, I am creting archive script in which i need to split the source file's to different target folder's based on the input file name first character. Input1.txt -- will contains file names that are needs to be Archive. Input1.txt A1213355 B2255666 C2254555 A6655444 C5566445 ... (2 Replies)
Discussion started by: kmsekhar
2 Replies

7. Shell Programming and Scripting

Move all files from source to destination directory based on the filename

Move all files starting with a specific name to different directory. This shell script program should have three parameters File Name Source Directory Destination Directory User should be able to enter ĎAB_CD*' in file name parameter. In this case all the files starting with AB_CD will... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

8. Shell Programming and Scripting

move contents from one file to another based on line number or content

I want a script that will move everything beyond a certain line number or beyond a certain content word into another file. For example, if file A has this: first line second line third line forth line fifth line sixth line I want to run a script that will move everything beyond the third... (4 Replies)
Discussion started by: robp2175
4 Replies

9. UNIX for Dummies Questions & Answers

how to move files into different folders based on filename

I need to move a bunch of files into folders that have the same name. I wanted to either do this with some filter command or some type of batch file that I could save that would already include all of the mv commands since I will have to do this process often. Whatever method you think is easier. ... (7 Replies)
Discussion started by: italia5
7 Replies

Featured Tech Videos