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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-17-2003, 04:55 PM
|
#1
|
LQ Newbie
Registered: Dec 2001
Posts: 7
Rep:
|
Simple BASH script
Hey.
I am trying to rename a couple of files containing the character "?" in their names. I want to replace "?" with "-".
I've tried -
for i in `find . -name *\?*' ; do mv "$i" "`echo $i | sed -e s/\?/\-/g`" ; done
DIDN'T WORK.
Can anyone offer a perl / sed / ANY script to accomplish the task?
Thanks.
|
|
|
01-17-2003, 06:45 PM
|
#2
|
Member
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771
Rep:
|
for i in $(find . -name '*\?*'); do mv $i $(echo $i | sed -e s/\?/-/g); done
Note:Wont work with whitespace in the filename.
|
|
|
01-18-2003, 05:13 AM
|
#3
|
LQ Newbie
Registered: Dec 2001
Posts: 7
Original Poster
Rep:
|
Thanks, but...
Thanks for the reply!
But I need it to work WITH white spaces..
Can you offer additional help?
|
|
|
01-18-2003, 07:15 AM
|
#4
|
Moderator
Registered: May 2001
Posts: 29,415
|
find . -name "*\?*"|while read raw; do
mv -f "${raw}" "$(echo ${raw} | tr "?" "-")"; done
Just make it a habit to*always* quote variables + a double quote can't be mistaken by a backtick and the use of $(action) is easier to spot than using backticks. Since it's a simple one char replacement I'm using "tr" instead of sed.
|
|
|
01-18-2003, 11:00 AM
|
#5
|
LQ Newbie
Registered: Dec 2001
Posts: 7
Original Poster
Rep:
|
Thanks
Thanks,
Worked perfectly.
Fio
|
|
|
01-18-2003, 04:26 PM
|
#6
|
Member
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771
Rep:
|
Good job, unspawn!!
|
|
|
All times are GMT -5. The time now is 12:58 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|