Register
It is currently Sat Aug 30, 2014 12:22 am

tricky whitespace help?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Oct 10, 2011 3:56 am   

Joined: Thu May 14, 2009 1:22 am
Posts: 5
I have a line:
Code:
for i in `find "${dirs[$b]}/" -type f | sort | sed 's/^[.]*$/\"&\"/g' | xargs -I "{}" basename "{}"`; do

It is supposed to get the files name (both path and file contain whitespace), but "Joe 3.dat" becomes "Joe" and "3.dat".
There are more than 500 files this will be used on at once, from 20 directories.

Because this doesn't work, that tells me there is a solution about half as long (which is my average). Please help?


Top
 Profile  
 PostPosted: Tue Oct 11, 2011 8:53 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
What do you think your sed command does? Cannot you use basename in the -exec of the initial find?


Top
 Profile  
 PostPosted: Wed Oct 12, 2011 4:57 am   

Joined: Thu May 14, 2009 1:22 am
Posts: 5
Found it, it was the IFS! The "for" loop has a problem with spaces, and the IFS (bash Internal Field Separator) needs to be adjusted.

Code:
   oldifs="$IFS"
   IFS=$(echo -en "\n\b")
   targs=${#clargs[*]}
   for (( b=0; b<$targs; b++ ));do
         for i in `find "${clargs[$b]}/" -type f -exec basename "{}" \; | sort`; do
            ln -s "${clargs[$b]}/$i" "$dest/$i"
         done
   done
   IFS="$oldifs"


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP