[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Batch rename files



A quick solution that pops out of my head, but it is pretty stupid,
and certainly not the easiest:

ls -1 > rename;
cat rename;
	group-1-member-01.txt  
	group-1-member-02.txt  
	group-2-member-01.txt  

vi rename; then do the following:

:1,$s/\([a-z]*\)\(-[0-9]-\)\([a-z\-]*\)\([a-z0-9\.]*\)/\1\2\3\4 result\2\4/g

:1,$s/^/mv /g

exit out vi, and cat rename:

	mv group-1-member-01.txt result-1-01.txt
	mv group-1-member-02.txt result-1-02.txt
	mv group-2-member-01.txt result-2-01.txt


chmod +x rename;

./rename


Hope this helps.

Shao.

Arcady Genkin [a.genkin@utoronto.ca] wrote:
> What would be the easiest way to rename a bunch of files
> 
> foo-[0-9]-bar-[0-9][0-9].txt
> 
> into
> 
> blah-[0-9]-[0-9][0-9].txt
> 
> Note, that all of the files have identical portions `foo-', `-bar-',
> and `.txt' in the filenames. Different are two numerical parts.
> 
> For example:
> ,----
> | group-1-member-01.txt
> | group-1-member-02.txt
> | ...
> | group-2-member-01.txt
> | ...
> `----
> 
> The resulting files should have an identical portion `blah', and
> retain the original numerical parts.
> 
> ,----
> | result-1-01.txt
> | result-1-02.txt
> | ...
> | result-2-01.txt
> | ...
> `----
> 
> Thanks for any suggestions!
> -- 
> Arcady Genkin                                 http://www.thpoon.com
> Nostalgia isn't what it used to be.
> 
> 
> -- 
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null
> 
> 

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


Reply to: