Rename files in sub directories with sequential numbers
I can rename a file with sequential numbers from 1 to N with this script:
The script begins with renaming a some.dat file to 1.dat.txt and goes on sequentially renaming other DAT files to 2.dat.txt, 3.dat.txt and so on.
This script works very well on my Linux system when I have one directory with all DAT files in it. But it cannot work when I have a parent directory with sub directories. My directory structure is like this:
Parent Directory and inside parent directory there are 20 more sub directories and inside those sub directories are the DAT files.
Is there any way I can modify the above script so that (I am in my parent directory and run this script) it takes in one sub-directory and renames all the files in that directory in sequential numbers say 1 to N, then goes to another sub-directory and renames from N+1 to M, then goes to third sub-directory and renames from M+1 to X and so on?
The auto-increment operator and the -v option of mv are not standard, so use zsh, ksh93 or bash to run the script.
I'm assuming there are no embedded newlines in the filenames.
If you want standard code, you should use something like this:
... and you should remove the -v option from the mv command.
P.S. I don't remember if read without varname is standard, to lazy to check it right now
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)
I have a file that looks like this:
n1 1
n2 1
n3 1
n4 3
n4 3
n2 5
n2 5
n2 5
n2 5
n3 5
n3 5
n4 6
n7 6
that is a name followed be a descriptive number.
I want to make these numbers sequential starting from 0 but without changing the "neighbours" each name belongs to. So the above... (3 Replies)
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... (1 Reply)
Hi,
I have a directory structure like below
Directoryname create time
d1 12:00
d2 12:05
d3 12:08
I want to read the directories based on timestamp.That is oldest directory must be read first and kick off certain process.
... (7 Replies)
Hi All,
I am looking for a simple way to write numbers to a file sequentially starting from 1 and ending on a specified upper limit. Example of the output file is below
Example
1
2
3
4
5
.
.
.
.
1000
please let me know the best way to do it. (10 Replies)
I have a huge collection of HTML files. They have their own file names with htmlextension. I want to rename each of these files with continuous numbers starting from 1.html till the last count of files. Simply it means that if there are three files like this
abc.html
cdfhg.html
rmbd.htmlthen... (1 Reply)
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)
Hi Unix gurus,
I have a file. I need to insert sequential number at the starting of the file. Fields are delimited by "|". I know the starting number.
Example:
File is as follows
|123|4test|test
|121|2test|test
|x12|1test|test
|vd123|5test|test
starting number is : 120
... (7 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)