LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-24-2005, 01:44 PM   #1
paskari
LQ Newbie
 
Registered: Sep 2005
Posts: 4

Rep: Reputation: 0
shell renaming script


I have looked over dozens of scripts for mass file renaming in the past 16 hours and all of them have one major flaw
They can't handle files with spaces in them like so:

"this is a picture.jpg"

I can't seem to get around this, I've tried using ls, ls | grep, dir, creating a buffer, enclosing it in quotes, and even sed still treats it as four different files.

someone please help me

thank you
 
Old 09-24-2005, 01:57 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Without knowing the scripts it's difficult to know the problem exactly but try setting $IFS to a newline first:
IFS="
"
 
Old 09-24-2005, 02:11 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Couldn't you do something like this:

Code:
#!/bin/bash

# Get wanted files. *txt (and maybe path to) should/could be changed
find . -name "*txt" | \
while read THISLINE
do
  # create new filename (space to dot in this case)
  SPACE2DOT="`echo ${THISLINE} | sed 's/ /./g'`"
  # move file
  mv "${THISLINE}" "${SPACE2DOT}"
done
Hope this helps.
 
Old 09-24-2005, 02:15 PM   #4
paskari
LQ Newbie
 
Registered: Sep 2005
Posts: 4

Original Poster
Rep: Reputation: 0
here's how I managed to do it:

Code:
#move all .jpg files
for i in *.jpg; do
	mv "$i" $srcDir/"$i"
done
turns out it's easier than I thought
 
  


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
Simple Renaming Script Boffy Programming 5 08-12-2005 09:07 AM
file renaming with shell script or ? XJNick Linux - General 5 07-29-2005 02:43 PM
directory renaming shell script? Apostasy Linux - General 15 02-22-2005 06:50 AM
renaming files script. xushi Programming 4 10-10-2004 08:06 AM
Need help with shell script - renaming multiple files NiallC Linux - Newbie 25 07-04-2004 10:45 AM


All times are GMT -5. The time now is 05:00 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration