|
bash script - variables & arrays question
I need to extract, rename and move a few files from a cascade of directories and subdirectories. Some names of files are known, others have to be found with the script.
It seems at some stage of the script, I need to save a directory name in a variable or a number of directory names in an array, then 'cut' a part of the name(s) and 'paste' it in following commands in order to rename and move the files to be saved to the top directory before removing everything else.
Found good tutorials on the net but no solution to this particular problem. Any help on what to include in script or hint about suitable 'howto' most welcome.
System is Red Hat 9
Here is the layout:
(all files relative to /home/user/job01/)
01 ~ no1/ -->keep
02 z_files/
03 important.html -->save as "no1/main.html"
04 a_dat/
05 important.gif -->save as 'no1/main.gif"
06 001_files/
07 sub_files/
08 some_da/
09 important.html -->save as "no1/001.html"
10 some_dat/
11 main.png -->save as "no1/001.png"
12 002_files
13 etc
14 100_files
15 ~no2/
16 etc
17 ~no300/
directory named 'no1' (on line 01) number about 300, all these names are known and are placed in an array
files to be saved on lines 03, 05, 09 and 11 are unique and easy to identify and process
directory named 001_files (on line 06) are unknown names but have a common ending (_files), the number of directories is also variable, the variable part of the name (001 in this case) will be used to rename the files to be saved
it is possible to issue the command "cd *_files from the ~no1/ directory which will enter any of these files, then save the first digits of the name ('001' in the example above) which can then be 'pasted' to the files to be saved from this directory, then remove this directory, then re-issue the same command that will enter the next random "*_files" directory and so on untill there is no more "_files" directory.
How to use and parse the portion of the name is what I don't know.
|