LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple SED with rename (https://www.linuxquestions.org/questions/programming-9/simple-sed-with-rename-924494/)

thund3rstruck 01-18-2012 04:08 PM

Simple SED with rename
 
just curious as to why this command fails to rename my files:

Code:

$ rename -v "s/HDTV.*/mkv/g" *.mkv
$ ls
Archer.S01E01.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E02.720p.HDTV.X264-LiLDiCK.mkv
Archer.S01E03.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E04.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E05.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E06.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E07.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E08.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E09.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E10.720p.HDTV.x264-immerse.mkv
idx.txt

I tested the sed expression and that works fine.

Code:

$ cat idx.txt && cat idx.txt | sed "s/HDTV.*/mkv/g"
Archer.S01E01.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E02.720p.HDTV.X264-LiLDiCK.mkv
Archer.S01E03.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E04.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E05.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E06.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E07.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E08.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E09.720p.HDTV.X264-DIMENSION.mkv
Archer.S01E10.720p.HDTV.x264-immerse.mkv

Archer.S01E01.720p.mkv
Archer.S01E02.720p.mkv
Archer.S01E03.720p.mkv
Archer.S01E04.720p.mkv
Archer.S01E05.720p.mkv
Archer.S01E06.720p.mkv
Archer.S01E07.720p.mkv
Archer.S01E08.720p.mkv
Archer.S01E09.720p.mkv
Archer.S01E10.720p.mkv

What am I missing? Does the rename command have some funky deal where it can't do RegEx?

Just wondering...

thanks in advance

jhwilliams 01-18-2012 04:27 PM

You probably have the old version of rename that doens't take a regex. You want the one from the Perl distribution.

thund3rstruck 01-18-2012 08:16 PM

Quote:

Originally Posted by jhwilliams (Post 4578294)
You probably have the old version of rename that doens't take a regex. You want the one from the Perl distribution.

Ugh... yup, Fedora rename program doesn't support RegExp

Code:

$ rename -V
rename from util-linux 2.20.1

Download Perl version of rename

http://forums.fedoraforum.org/showthread.php?t=199949
http://wiki.linuxquestions.org/wiki/Rename

Wow that's so weak!

Thanks....

David the H. 01-19-2012 09:00 AM

As mentioned, the "rename" that uses that syntax is actually the prename perl script. It comes standard with the perl package, in Debian-based systems at least, and it's automatically aliaed to rename through the alternatives system.

If you have perl installed on Fedora or another non-debian system, I really want to know if also supplies prename for you too, but just doesn't set it up as the default.

thund3rstruck 01-19-2012 10:06 AM

Quote:

Originally Posted by David the H. (Post 4578864)
If you have perl installed on Fedora or another non-debian system, I really want to know if also supplies prename for you too, but just doesn't set it up as the default.

I have perl installed and I had no prename script. I had to download it manually and then move it to /usr/local/bin

Code:

$ locate prename
/home/lisa.bailey/Downloads/prename.txt
/usr/local/bin/prename

$ find / -type f -iname prename* 2>/dev/null
/usr/local/bin/prename
/home/lisa.bailey/Downloads/prename.txt



All times are GMT -5. The time now is 12:34 AM.