LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   removing the dash within the name of multiple files (https://www.linuxquestions.org/questions/linux-general-1/removing-the-dash-within-the-name-of-multiple-files-911729/)

kaplan71 11-03-2011 03:43 PM

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?

macemoneta 11-03-2011 04:00 PM

Code:

rename '-' '' * ; rename '--' '' *

kaplan71 11-03-2011 04:04 PM

Thanks...It worked.

David the H. 11-04-2011 07:17 AM

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

kaplan71 11-07-2011 12:58 PM

Hi there --

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


All times are GMT -5. The time now is 03:54 PM.