Rename the files in all the directories and sub-directories
Hi all,
I have more than 12000 files in 46 different directories and each directory has 2 sub-directories named “dat” or “gridded”. Dat sub-directories have files with extension “jpg.dat” and gridded sub-directories have files with extension “.jpg”.
I need to rename all the files (some parts to be replaced or removed and most of the parts to be rearranged) in all the directories and sundirectories.
In the new name, words come in this order with these changes:
(1) “gridded” needs to be replaced with “tom” (in all the files from all the gridded subdirectories).
(2) “MMS” needs to come just after “tom” and it can also be “RM” instead of “MMS”
(3) “yihF-b3861” word will be different in every file
(4) “plate1” will be replaced with “1”. It can be “plate2” which needs to be replaced by “2”
(5) “set1” needs to be replaced with “[1-4]”. It can be set2, set3 or set4 and needs to be changed [2-4], [3-4] or [4-4] respectively.
(6) “ DNA433-c1-384-20110301” part will different in each file. It needs to be renamed to “ DNA433-20110301” but the “c1-384” which needs to be removed, is same in every file.
(7) File extensions “.jpg” or “.jpg.dat” remains the same.
Remaining part of the old name (i. e. -Tp32-CmKan-Sel2-384-) will be left out or deleted.
Thanks in advance. I appreciate your time.
Last edited by Scott; 05-15-2013 at 05:41 PM..
Reason: Code tags, not Icode tags
I could write a write a script which does the task but the problem is, it works only on the files which are present in the current directory. I need it to be working on subdirectories as well.
Here is the script: for file in $(find -type f -name "*.jpg")
do
echo $file
newfile="$(echo $file | sed -e 's/gridded-//g' -e 's/-c1-384-/_/g' -e 's/-Tp32-CmKan-Sel2-384-/_/g' -e 's/-32C-/_/g' | sed 's/\(.*\)-\(.*\)-\(.*\)_\(.*\)_\(.*\)_\(.*\)-\(.*\)\.\(.*\)/\5_\2_\7_\6_\3-\4\.\8/' | sed -e 's/^/mohan_dm-/')"
echo $newfile
cp $file $newfile
done
It successfully prints the changed names of the files from subdirectories (echo $newfile) but does not make a copy of files in the subdirectories. That means "cp $file $newfile" is not working.
Hi,
Friends, i have a requirement where i need to rename my files residing in multiple sub directories and move them to one different directory along with some kind of directory indicator.
For eg:
test--is my parent directory and it has many files such as
a1.txt
a2.txt
a3.txt
... (5 Replies)
how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex.
so
mydemo--2015-03-23-1500.tar.gz
> database
-... (5 Replies)
Can anyone come up with a unix command that lists
all the files, directories and sub-directories in the current directory
except a folder called log.?
Thank you in advance. (7 Replies)
I can rename a file with sequential numbers from 1 to N with this script:
num=1
for file in *.dat;do
mv "$file" "$(printf "%u" $num).txt"
let num=num+1
done
The script begins with renaming a some.dat file to 1.dat.txt and goes on sequentially renaming other DAT files to... (1 Reply)
Hi legends,
I am writing a script, in that my requirement is, if all the fill types stored in one directory from that we need to separate different different directories based on the file types.
for example in a directory(anish). 5 different types files
1- directory
2- .txt files
2- .sh... (1 Reply)
Hi,
Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process.
I wanted to disply using a unix command all the directories recursively excluding files.
I tried 'ls -FR' but that display files as... (3 Replies)
Hello guys,
I was looking for a shell script that removes all the special characters from the files and the subdirectories recursively. I could not locate it any more. Dose any body have a similar script that dose that?
Thanks for the help.
AV (0 Replies)
Hi,
This is what I would like to do.
1. Find all directories named "ByHost" in a specified directory
2. Rename all .plist files inside "ByHost" directories
This is the way I have been able to do it so far.
#!/bin/sh
#
# Rename ByHost files
#
# Thomas Berglund, 13.07.08
# Get the... (2 Replies)
i have hundreds of directories that have to be renamed. the directory structure is fairly uniform which makes the scripting a little simpler.
suppose i have many directories like this */*/*/*abc* (in other words i have similar directory names 3 dirs deep that all contain the pattern abc in... (8 Replies)