Re: [Help] Renaming files through bash shell scripts

Baskar Selvaraj <baskar-FaTCxNPFk8w/[email protected]>
Newsgroups gmane.org.user-groups.linux.ilugc
Message-ID <CACtiFJZc=4QFfBHq-LM2zvV4rNGF8Dn=TqMM+cRNUQBrvcLfMg@mail.gmail.com>
> === test.rb ===
>
> #!/usr/bin/env ruby
>
> Dir.glob("*.mp4").each do |f|
>   new_f = f.dup
>   new_f[3] = (f[1].to_i - 1).to_s
>
>   File.rename(f, new_f)
> end
>
> === END ===

Hi,

Thanks for the script

The scripts works, but the results were different, if the value after L is < 10.

input:

M1L01.mp4
M1L02.mp4
M1L03.mp4
M1L04.mp4
M1L05.mp4
M2L01.mp4
M2L02.mp4
M2L03.mp4
M2L04.mp4
M2L05.mp4
M3L01.mp4
M3L02.mp4
M3L03.mp4
M3L04.mp4
M3L05.mp4

Output:

M1L01.mp4
M1L02.mp4
M1L03.mp4
M1L04.mp4
M1L05.mp4
M2L11.mp4
M2L12.mp4
M2L13.mp4
M2L14.mp4
M2L15.mp4
M3L21.mp4
M3L22.mp4
M3L23.mp4
M3L24.mp4
M3L25.mp4

S. Baskar
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
ILUGC Mailing List Guidelines:
http://ilugc.in/mailinglist-guidelines
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.