nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

read not preserving double spaces

This is a discussion on read not preserving double spaces within the Shell scripting forums, part of the Development/Scripting category; Hi, I am trying to rename files but when I get to the "read" command the double spaces in the ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 09-03-2008, 11:04 PM
Junior Member
User
 
Join Date: Sep 2008
My distro: Debian
Posts: 2
Rep Power: 0
bincode1010 is on a distinguished road
Default read not preserving double spaces

Hi,

I am trying to rename files but when I get to the "read" command
the double spaces in the filenames are not preserved and I end up with a
single space and the file rename fails.

code:

while read LINE
do
md5hash="$(echo $LINE | cut -c1-16)"
filename="$(echo $LINE | cut -c18- |sed 's/\.doc//'|sed 's/^/"/')"
fullname="$(echo $LINE | cut -c18- |sed 's/^/\"/'|sed 's/$/"/')"
echo mv $fullname $filename-$md5hash-$user\.doc\" >> md5rename
done < md5files

contents of md5rename file:

138fa9a642ec50fe /home/darc/cache/Customer Service Rx for Sub.doc
ffcfcf86b6216988c /home/darc/cache/BERGEN NJADONA march.doc
dc21ffbe22ecc83e /home/darc/cache/BERGEN NJADONA June.doc
1ba29dab24f2134e /home/darc/cache/BERGEN NJADONA January.doc
bf103cc1895b118d /home/darc/cache/BERGEN NJADONA may.doc


thanx,

awesome site!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-21-2008, 02:23 PM
Junior Member
User
 
Join Date: Feb 2008
My distro: .
Posts: 10
Rep Power: 0
unSpawn is on a distinguished road
Default

Temporarily set up your IFS w/o space?
Reply With Quote
  #3 (permalink)  
Old 09-26-2008, 05:49 AM
Junior Member
User
 
Join Date: Sep 2008
My distro: Debian
Posts: 2
Rep Power: 0
bincode1010 is on a distinguished road
Default

i ended up doing that.

echo "remove whitespace from file names"
ls $cachedir | grep -e "[:alnum:]" | \
while read i; do
j=`echo -n "$i" | sed -e 's/ /_/g'`
mv "$cachedir/$i" "$cachedir/$j"
done
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
USB Port Blocking / Read only Acces on Windows rajuk Windows Xp/2000/2003 server administration 4 06-09-2008 12:13 AM
Read one integer from a file, cannot find info beginer Shell scripting 1 05-13-2008 06:44 PM
Read unix partition table sweta Solaris/OpenSolaris 1 02-05-2007 07:51 PM
The source seems encrypted and can't be read. Are you try to raj Linux hardware 1 01-03-2007 08:59 AM
How do I Double KDM (KDE) Login Screens? tom Linux software 1 06-09-2005 03:34 PM


All times are GMT +5.5. The time now is 02:31 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36