Batch cycle and move files, please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Batch cycle and move files, please help
# 1  
Old 01-09-2016
Batch cycle and move files, please help

Hi guys, I'm not a great programmer but I do this project with a cool data and it has tons and tons of files which I need to sort before I can work with it.

The problem I need to solve is to move all files that look like

Code:
/X/Y/A_BC.xml

to

Code:
/X/B/A/Y/BC.xml

So it involves cycling through directories, reading filenames and creating new directories out of filenames. If you give me the solution for this exercise I'll do the rest myself of course.

I tried high-level languages, it takes too long. I need some kind of shell script for that.

Thanks!

Last edited by Scrutinizer; 01-09-2016 at 01:14 AM.. Reason: CODE tags
# 2  
Old 01-09-2016
Hi, where does the directory name "B" come from? Is that somehow derived from the original file name, or is it always B.

Also: what OS and shell are you using?
# 3  
Old 01-09-2016
additional info

so I run this on my mac or on a remote server with some unix system (I'm using university resources), don't remember which one exactly

I need to read part of the filename and make a respective directory and put the file in there. I can identify part1 from the filename, because it has to be first 6 digits, the rest is part2_part3.

Code:
/dir1/dir2/part1part2_part3.xml

to

Code:
/dir1/part1/dir2/part2_part3.xml

roughly.

here's an example:
Code:
/levelone/level2/123456789_1.xml

to
Code:
/levelone/123456/level2/789_1.xml

I need to do that for all files in a given directory

Last edited by Scrutinizer; 01-09-2016 at 01:58 AM.. Reason: CODE tags
# 4  
Old 01-09-2016
The case in post #3:
Code:
/dir1/dir2/part1part2_part3.xml

to
Code:
/dir1/part1/dir2/part2_part3.xml

differs from the one in post #1:
Code:
/dir1/dir2/part1_part2part3.xml

to
Code:
/dir1/part2/part1/dir2/part2part3.xml

which one is it?

Last edited by Scrutinizer; 01-09-2016 at 02:41 AM..
# 5  
Old 01-09-2016
First one
# 6  
Old 01-09-2016
So then part2 consists of 6 digits? Could you create an example?
# 7  
Old 01-09-2016
Sorry for the confusion. The exact ordering does not really matter. This example would be enough I think:

move blablabla/folder/123456123_456.xml

to blablabla/123456/folder/123_456.xml
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

2. Shell Programming and Scripting

Accessing files in batch

hai, I have a list of files having extension .sy in a folder. I want to find such files and print the first two columns of the files to new extension .tmp (1 Reply)
Discussion started by: sreejithalokkan
1 Replies

3. Shell Programming and Scripting

Need to exclude .NFSxxx files in clear old files batch script

I am new to Shell Scripting and need some help. The following batch job has been failing for me due to the .nfsxxx files in use. I need to know how to modify the following script to exclude the .nfsxxx files so this batch job will not fail on me. I have done lots of googling and keep coming back... (2 Replies)
Discussion started by: kimberlyg2007
2 Replies

4. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

5. OS X (Apple)

Batch file to move video files and retain sub-directories

I have just purchased my first ever Apple computer - and am therefore new to UNIX also. I would like to create a simple "batch file" (apologies if this is the wrong terminology) to do the following: When I plug my camera into the MAC it automatically downloads photos and videos into a new... (1 Reply)
Discussion started by: mm0mss
1 Replies

6. Shell Programming and Scripting

Batch job in unix server to move the pdf file from unix to windows.

Hi Experts, I have a requirement where i need to setup a batch job which runs everymonth and move the pdf files from unix server to windows servers. Could some body provide the inputs for this. and also please provide the inputs on how to map the network dirve in the unix like that... (1 Reply)
Discussion started by: ger199901
1 Replies

7. UNIX for Dummies Questions & Answers

Batch Renaming of Files

Hello all, thanks for your time (and this forum, what an awesome resource for newbs like myself!) Anyways, I've been given the task of importing content from a directory of about...7000 HTML files. They are all named appropriately and broken down by name depending on what book they belong too.... (8 Replies)
Discussion started by: gratefulhokie
8 Replies

8. Shell Programming and Scripting

Looping/Repetition in Batch files

Hi All, I'm just new to UNIX, does anyone know how to create a batch file in UNIX that does the following routines: 1.) process multiple files in a directory in DOS, I set my sample input file as: set INPUTFILE=%1 in UNIX>> ???? 2.) every file to be processed by executing a program... (2 Replies)
Discussion started by: kimpot7268
2 Replies

9. UNIX for Advanced & Expert Users

Looping/Repetition in Batch files

Hi All, I'm just new to UNIX, does anyone know how to create a batch file in UNIX that does the following routines: 1.) process multiple files in a directory in DOS, I set my sample input file as: set INPUTFILE=%1 in UNIX>> ???? 2.) every file to be processed by executing a program... (1 Reply)
Discussion started by: kimpot7268
1 Replies

10. UNIX for Dummies Questions & Answers

Batch files and FTP under Unix

Hey all, Does anyone know if Unix has an equivalent to a batch file? And if so, does it work the same way as a batch file under windows? AND, if you can answer that one, is it possible to run such a file under HP-UX and have it execute while in an FTP command line? What I need to do is... (4 Replies)
Discussion started by: ober5861
4 Replies
Login or Register to Ask a Question