LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-22-2012, 08:53 AM   #1
lghizoni
Member
 
Registered: Dec 2011
Location: Denmark
Distribution: Slackware, Debian
Posts: 102

Rep: Reputation: Disabled
Shell command to rename multiple archives


Hello all,

I'm a Debian user. I do have 1148 txt archives with different names, and I want to change their names. More specificaly, I just want to delete 1 letter from the archives. The names are:

WFI_FM1_DB_OD_B13_G100_I25_20120227_R_M_1_002.txt
WFI_FM1_DB_OE_B14_G100_I75_20120227_R_M_1_002.txt
WFI_FM1_DB_OD_B15_G159_I50_20120227_R_R_5_006.txt
WFI_FM1_DB_OD_B15_G159_I50_20120227_R_R_4_005.txt
WFI_FM1_DB_OD_B13_G100_I25_20120227_R_M_2_003.txt
WFI_FM1_DB_OE_B14_G100_I75_20120227_R_M_2_003.txt

etc...and I want to delete that R.

Does anyone know how to do it in shell with one command??

Thanks!

Last edited by lghizoni; 05-22-2012 at 08:56 AM.
 
Old 05-22-2012, 09:57 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Should be fairly easy. The "rename" command may or may not do what you want it to do - I've found it to vary wildly between different distros. See what "man rename" says. However, otherwise you should be able to run this:

Code:
for i in WFI_FM1*.txt; do
    mv $i $(echo $i | sed 's/_R\(_[^_]\+_[^_]\+_[^_]\+.txt\)$/\1/')
done;
I don't know exactly what defines the archives' names, but these are the assumptions I've made:
  • They all begin with WFI_FM1 and end in .txt
  • The _R that you want to remove is followed by "_<some characters>_<some characters>_<some characters>.txt".

If these two are true, then the code should do what you want it to do. Hope this helps,
 
Old 05-22-2012, 12:35 PM   #3
lghizoni
Member
 
Registered: Dec 2011
Location: Denmark
Distribution: Slackware, Debian
Posts: 102

Original Poster
Rep: Reputation: Disabled
It works great!! Thank you!

Cheers.

Quote:
Originally Posted by Snark1994 View Post
Should be fairly easy. The "rename" command may or may not do what you want it to do - I've found it to vary wildly between different distros. See what "man rename" says. However, otherwise you should be able to run this:

Code:
for i in WFI_FM1*.txt; do
    mv $i $(echo $i | sed 's/_R\(_[^_]\+_[^_]\+_[^_]\+.txt\)$/\1/')
done;
I don't know exactly what defines the archives' names, but these are the assumptions I've made:
  • They all begin with WFI_FM1 and end in .txt
  • The _R that you want to remove is followed by "_<some characters>_<some characters>_<some characters>.txt".

If these two are true, then the code should do what you want it to do. Hope this helps,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple sources for creating archives with tar sepehr Programming 3 12-17-2010 01:07 AM
shellscript to extract multiple archives quackyo Programming 13 04-27-2009 05:39 AM
shell command for bulk 'rename' anon201 Linux - Newbie 5 12-17-2008 03:46 AM
Zip multiple directories to seperate archives PlymWS Linux - Software 3 06-16-2007 04:40 AM
UNIX shell script: split long command on multiple lines loopoo Linux - Newbie 2 10-23-2006 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration