Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rot 13'ing all file extensions in a folder

44 views
Skip to first unread message

lloyd

unread,
Nov 10, 2012, 9:11:26 PM11/10/12
to
Could anyone provide a simple script to rot 13 all file extensions
(all alphabetic characters after the last period, preserving case) in
the current directory?

Sorry not to even try myself. It's been years. I don't mind which
flavour of shell. Thanks.

Janis Papanagnou

unread,
Nov 10, 2012, 9:28:45 PM11/10/12
to
On 11.11.2012 03:11, lloyd wrote:
> Could anyone provide a simple script to rot 13 all file extensions
> (all alphabetic characters after the last period, preserving case) in
> the current directory?

One possibility (with modern shells)...

for f in *.*
do
ext=$( tr "a-zA-Z" "n-za-mN-ZA-M" <<< "${f##*.}" )
mv -i "$f" "${f%.*}.${ext}"
done


Janis

lloyd.h...@gmail.com

unread,
Nov 10, 2012, 9:44:15 PM11/10/12
to
Janis Papanagnou wrote:

>> Could anyone provide a simple script to rot 13 all file extensions
>> (all alphabetic characters after the last period, preserving case) in
>> the current directory?
>
> One possibility (with modern shells)...
>
> for f in *.*
> do
> ext=$( tr "a-zA-Z" "n-za-mN-ZA-M" <<< "${f##*.}" )
> mv -i "$f" "${f%.*}.${ext}"
> done

Thanks so much Janis! This is very clever.

David Combs

unread,
Dec 7, 2012, 7:31:16 PM12/7/12
to
In article <3db525ba-57f9-41ec...@googlegroups.com>,
gnu Emacs has some nice stuff for that kind of thing.

Here are some notes to myself:

(01)(06)(09).mp3 09 06 01
army style: dayNum=1 monthNum=2 YrNum=3
sortable: YrNum=3 monthNum=2 dayNum=1

(dired-do-rename-regexp "\\(globalresearch\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\).mp3" "GR-\\3\\2\\4.mp3")
(dired-do-rename-regexp "\\(GR-\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\).mp3" "\\1\\4\\3\\2.mp3")

I use the above to change the name of .mp3-files from a particular
place (globalResearch.ca -- HAVE A LOOK!) to change the format
and order of date parts so that they'll sort, ie be listed in
the order I want, thata is, by date (I rearrange the date and
move it to the left side of the file-name).


where that function is described (by emacs) as:

| % R runs the command dired-do-rename-regexp
| which is an interactive compiled Lisp function in `dired-aux.el'.
| It is bound to % r, % R, <menu-bar> <regexp> <rename>.
| (dired-do-rename-regexp regexp newname &optional arg whole-name)
|
| Rename selected files whose names match regexp to newname.
|
| With non-zero prefix argument arg, the command operates on the next arg
| files. Otherwise, it operates on all the marked files, or the current
| file if none are marked.
|
| As each match is found, the user must type a character saying
| what to do with it. For directions, type C-h at that time.
| newname may contain \<n> or \& as in `query-replace-regexp'.
| regexp defaults to the last regexp used.
|
| With a zero prefix arg, renaming by regexp affects the absolute file name.
| Normally, only the non-directory part of the file name is used and changed.




Another emacs example is this function (via dired-x.el, I think):

*** WDIRED: M-x wdired-change-to-wdired-mode --> mode-line: "[(Editable Dired)]" dired-edit
rename files via simply **EDITING** the names IN THE DIRED BUF ITSELF!
Command: Toggle Dired-Omit mode.


Hope this helps SOMEONE!

David

0 new messages