One liner for renaming files

D

D. Alvarado

Hello,
I am looking for a one line command that I could run with perl to
rename a group of files. The desired outcome is

start end
----- ---
ctf_005.liv ctf05cae002.liv
ctf_006.liv ctf05cae003.liv
ctf_007.liv ctf05cae004.liv
ctf_008.liv ctf05cae005.liv

and so on.

Any advice is greatly appreciated, - Dave
 
T

Tad McClellan

D. Alvarado said:
I am looking for a one line command


Why restrict it to one line?

If someone has a two-line solution, they should not post it?

that I could run with perl to
rename a group of files. The desired outcome is

start end
----- ---
ctf_005.liv ctf05cae002.liv
ctf_006.liv ctf05cae003.liv
ctf_007.liv ctf05cae004.liv
ctf_008.liv ctf05cae005.liv

and so on.

Any advice is greatly appreciated, - Dave


Get it working with many lines of code first, then pare it
down to one line. Post here if you get struck.

An example is not a specification. It would be helpful if you
described what transformation you want to have made...
 
C

Charles DeRykus

Hello,
I am looking for a one line command that I could run with perl to
rename a group of files. The desired outcome is

start end
----- ---
ctf_005.liv ctf05cae002.liv
ctf_006.liv ctf05cae003.liv
ctf_007.liv ctf05cae004.liv
ctf_008.liv ctf05cae005.liv


perl -e 'for (@ARGV){($to=$_)=~s/_(\d+)/sprintf "05cae%03d",$1-3/e; \
rename $_,$to or warn $!}' ctf_*.liv

People can go mad on the golf course though so you might want to
create a more general utility and save it to a file. There are
simply too many things that go wrong with one-liners unless they're
simple.

hth,
 
P

parv

I am looking for a one line command that I could run with perl to
rename a group of files. The desired outcome is

start end
----- ---
ctf_005.liv ctf05cae002.liv
ctf_006.liv ctf05cae003.liv
ctf_007.liv ctf05cae004.liv
ctf_008.liv ctf05cae005.liv

and so on.

Following would be overkill many times over for you then...

Efforts of some others...

http://perlmonks.org/index.pl?node_id=303814
http://perlmonks.org/index.pl?node_id=277174


...and to toot my own horn...

Distribution:
http://www103.pair.com/parv/comp/src/perl/sanename
http://www103.pair.com/parv/comp/src/perl/dist/File-Name-Sanitize-1.01.tar.gz
http://www103.pair.com/parv/comp/src/perl/dist/Parv-Util-1.10.tar.gz

Pod:
http://www103.pair.com/parv/comp/src/perl/pod/sanename.pod
http://www103.pair.com/parv/comp/src/perl/pod/File-Name-Sanitize.pod
http://www103.pair.com/parv/comp/src/perl/pod/Parv-Util-Compile.pod


- parv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,880
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top