Bulk rename directories names - regex

Trying to use GPRename for rename some directories quickly but no success.
I have some directories named with artist names like "StevieRayVaughan" and i need rename it to "Stevie Ray Vaughan".
Is some way to make it happen in bash/regular expression? space before upper letters?
Thank you.

There is a tool called perl-rename sometimes called rename - not to be confused with rename from util-linux.
This tool take a Perl expressions and renames accordingly:
perl-rename 's/(?<!^)(?=[A-Z])/ /g' *
The above will rename all files / directories in the current directory to add spaces before uppercase letters:
helloWorld -> hello World
John Doe -> John Doe
You can try the regex online

Related

Batch rename files with regex not working

I've got many files on a linux server which have this format
text_text_mixturelettersnumbers.filefor example Hesperocyparis_goveniana_E00196073A.bam.baior Hesperocyparis_forbesii_RBGEH19_bwa_out.txt. I would like to change the first underscore to a hyphen and leave everything else so it looks like this text-text_mixturelettersnumbers.file.
I have tried rename -n 's/(\w+)_(\w+_.)/$1-$2/' * and many different versions thereof but nothing is happening. Could someone please point out what I've got wrong?
Thanks
Markus
The util-linux rename does not have an option to display the results only. It is very basic.
If you want to list the files that contain two underscores before an extension, use
for f in *_*_*.*; do
echo "$f => ${f/_/-}";
done
To actually rename, use mv:
for f in *_*_*.*; do
mv -- "$f" "${f/_/-}";
done
The "${f/_/-}" replaces the first _ with - in variable f.

Regular expression selection of last two folder path names

Im working in perl but I am having some issues with cutting out the other folder names to leave the last two folder names.
Trainings and Events
General Office\Archive
General Office\Office Opperations\Contacts
General Office\Office Opperations\Office Procedures\How Tos
public_html\Accordion\.svn\tmp\text-base
I would like to remove the folder path names so the folders will end up like this with the last two path names for each:
Trainings and Events
General Office\Archive
Office Opperations\Contacts
Office Procedures\How Tos
tmp\text-base
Office Opperations\Contacts
Ive read some other stackoverflow that showed the last two folder names picked out, but I cannot reverse the expression. (I will link it if I can find it)
I am using sublime text 3 currently to test my expressions.
Thank you
The pattern you want is
s/.+\/(.+\/.+)$/$1/g
It'll grab the last bit of the folder name and replace the whole string with it.
(?:[^\\]*\\|^)[^\\]*$
You actually want "up to two", because otherwise you won't catch "Training and Events". To solve this, I match the two cases separately:
Either a folder name (any number of non-backslashes) followed by a slash, or start of the string
Another folder name
End of string

Mass rename in shell script

I have a bunch of files which are of this format:
blabla.log.YYYY.MM.DD
Where YYYY.MM.DD is something like (2016.01.18)
I have quite a few folders with about 1000 files in each, so I wanted to have a simple script to rename them. I want to rename them to
blabla.log
So basically, I'm just stripping the date at the end. Here is what I have:
for f in [a-zA-Z]*.log.[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]; do
mv -v $f ${f#[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]};
done
This script outputs this:
mv: `blabla.log.2016.01.18' and `blabla.log.2016.01.18' are the same file
For more information:
I'm on windows, but I run this script in gitbash
For some reason, my gitbash doesn't recognize the "rename" command
Some regex patterns (like [0-9]{4} don't seem to work)
I'm really at a lost. Thanks.
EDIT: I need to rename every single file that has a date at the end and that is of the from: *.log.2016.01.18. They all need to keep their original names. All that should change is the removal of the date.
You have to use % instead of #: you want to remove from the end, not the start of your string.
Also, you're missing a . in what has to be removed, you don't want to end up with blabla.log..
Quoting the variable names prevents surprises when file names contain special characters.
Together:
mv -v "$f" "${f%.[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]}"

Matching periods in a string to underscores in a string

I am working on creating a bash script to automatically place videos in a Plex Library. For shows that ive seen so far, the following regex works fine to detect the show name, season, and episode number.
#TV Show Name
sed -n 's/\(.*\).S[0-9]\{1,\}.*/\1/p'
#TV Show Season
sed -n 's/.*\(S[0-9]\{1,\}\).*/\1/p'
#TV Show Episode
sed -n 's/.*S[0-9]*\(E[0-9]*\).*/\1/p'
The real trouble comes when moving the videos to the Plex Library. All the videos that are being placed in folder to be processed by the script use periods '.' as spaces.
For example,
Once.Upon.A.Time.S01E01.avi, Marvels.Agents.Of.S.H.I.E.L.D.S01E01.avi, etc
Since the Plex Library format uses underscores '_' to represent spaces (this is on a Linux server), I just use sed to replace the periods in the TV Show name with underscores. I then use grep -i to match it with the correct folder containing the TV Show in the Plex Library folder and use the rest of the show/episode number to put the file in the right place. Funny enough, one of the shows (Marvel's Agents of S.H.I.E.L.D. in fact) happens to come with periods in its name.
Is there an easy way to match together the file name and the plex folder name without having the underscore problem described above?
Or should I simply set an exception for this particular show?
If you take the show name as it exists prior to converting dots to underscores and convert all dots to question marks instead (e.g. sed "s/\./\?/g") you can then feed that name (e.g. Marvels?Agents?Of?S?H?I?E?L?D) to find to locate the appropriate Plex Library directory.
find /path/to/library -type d -iname "Marvels?Agents?Of?S?H?I?E?L?D"
That should give you the directory you need for moving the file and would also allow you to work backwards to properly convert the dots in the file name to underscores, if desired.

Rename a bunch of folders

I have a bunch of folders in the same directory
2012-12-06 Camcorder_5th_Jan_2013
2012-12-07 Camcorder_5th_Jan_2013
2012-12-16 Camcorder_5th_Jan_2013
...
I wish to drop the Camcorder_5th_Jan_2013 part and for them to look like:
2012-12-06
2012-12-07
2012-12-16
...
I was thinking something like
> mv (*).Camcorder* 1
i.e. capture everything before Camcorder and put into group 1 and rename to this group.
But I am struggling.
Any tips?
Thanks
replace match \s.+ with empty string
I suggest using rename, I am currently not in front of my Linux machine but hopefully these two links can get you somewhere:
Howto: Linux Rename Multiple Files At a Shell Prompt
http://www.cyberciti.biz/tips/renaming-multiple-files-at-a-shell-prompt.html
linux batch rename directories and strip # character from name
Update:
If you have access to Gnome or the X-Environment maybe you could try something like this if the Bash syntax is giving you a headache.
Métamorphose : A File -n- Folder Renamer:
http://file-folder-ren.sourceforge.net