LinuxQuestions.org
Review your favorite Linux distribution.
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 11-03-2011, 03:43 PM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
removing the dash within the name of multiple files


Hi there --

One of the directories on one of our servers, running Red Hat Enteprise 5, contains a series of files, similar in name, that contain a dash within the file name. Several examples are shown below:

Quote:
CTI.352-62--25.6989-22.6
CTI.352-62--25.6989-22.7
CTI.352-62--25.6989-22.8
I want to rename the files so they read as follows:

Quote:
CTI.3526225.6989-22.6
CTI.3526225.6989-22.7
CTI.3526225.6989-22.8
What command syntax, ie: for loop script, can I use to accomplish this?
 
Old 11-03-2011, 04:00 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Code:
rename '-' '' * ; rename '--' '' *
 
Old 11-03-2011, 04:04 PM   #3
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Thanks...It worked.
 
Old 11-04-2011, 07:17 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Caution. There are at least two different programs called rename, with different syntaxes. Many debian-based systems use a perl-based version with "s///" style replacement patterns. Check the man page first.

You could also simply use a loop with an appropriate parameter expansion.

Code:
for file in CTS* ; do mv "$file" "${file/--}" ; done
 
Old 11-07-2011, 12:58 PM   #5
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Hi there --

I had a chance to try the for loop in another situation, and it worked as well. Thanks.
 
  


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
LXer: Keep Files From Showing Up In Unity (Dash) Or Other Programs That Use Zeitgeist With Activity LXer Syndicated Linux News 0 05-17-2011 08:11 PM
manually removing the .vdi files left over after removing VirtualBox adityavpratap Linux - General 2 10-24-2010 12:04 PM
Removing multiple files in nested directories... cwwilson721 Slackware 7 04-02-2008 08:44 AM
Removing files wihtout removing containing Direcotry caps_phisto Linux - General 2 10-07-2004 08:16 AM
Removing multiple packages tipaul Slackware 8 08-21-2004 09:45 AM

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

All times are GMT -5. The time now is 06:04 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