LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 09-06-2016, 05:46 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Difficulty with rename


I am having trouble with using rename.

Trying to remove spaces and dashes from file names.

I thought all I had to do was add /char to be deleted/

rename "s/ //-//g" *
 
Old 09-07-2016, 01:58 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,258
Blog Entries: 3

Rep: Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713
Quote:
Originally Posted by Fixit7 View Post
I am having trouble with using rename.

Trying to remove spaces and dashes from file names.

I thought all I had to do was add /char to be deleted/

rename "s/ //-//g" *
There are two important things about "rename". The first is that you can run it with the -n option to test your patterns before actually applying them. The other is that the part inside the quotes can be any perl expresssions at all. You could even write a short program or routine inside the quotes and it would work.

But the part you are looking for is the substitution operator. The details are found in the manual page perlop
The dividers are usually slashes ( / ) but can be pretty much any character that is repeated three times.

Code:
s/old/new/
s/old//
The first case replaces "old" with "new" whereas the second case simply deletes "old" by replacing it with nothing.

So you are looking for any character in a set consisting of a space or a dash. That's written like [ -]
with the square braces delimiting the set. And, I presume, you want to zap every last occurrence in the file name. So you'll need the g modifier, to tell it to keep matching through the end of the string (file name).

Code:
rename -n 's/[ -]//g' ./*
When you have the results you wish, remove the -n

If you want to see more of what "rename" can do, look up some material on perl regular expressions. They are quite useful.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
if else difficulty Fixit7 Linux - General 24 01-15-2016 01:41 PM
Difficulty getting association Haines Linux - Networking 9 03-26-2015 01:57 PM
Mail difficulty Fixit7 Puppy 9 03-05-2015 11:44 AM
difficulty enios LinuxQuestions.org Member Intro 5 08-30-2011 11:50 PM
Rename network interface (Rename ppp0 ...) Nicolas1390 Linux - Newbie 2 08-08-2011 02:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

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