find & dirname:problems with white spaces in Directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find & dirname:problems with white spaces in Directories
# 1  
Old 05-07-2009
find & dirname:problems with white spaces in Directories

Hi all,

my problem:
(little extract from my bash-script)
I want to move each file (.mov) from one directory (and many Subdirectories) to another directory (only one);

after moving i want to create hardlinks to the old directories.

Thatīs no problem, but now:

source-directories includes (not all) white spaces (i.e. /Capture Scratch/)
I have tried:
Code:
#! /bin/sh

while true 
do if test `ls -R | wc -l` -ne 0 
	then for i in `echo $(find /Volumes/Movies/FCP -not -iname ".*" -not -iname "*-av.mov")` 
		do
				FILENAME=`basename $i`				
				PFAD=`dirname $i`
				TARGFOLDER="/Volumes/Movies/test/"
				size1=`ls -l "$i" | tr -s ' ' | cut -d ' ' -f5` 
          		sleep 2 
          	if test -f "$i" 
            	then size2=`ls -l "$i" | tr -s ' ' | cut -d ' ' -f5` 
            	if test $size1 -eq $size2 
            		then 	
	       	 		mv "$i" "$TARGFOLDER$FILENAME" 
	         		ln "$TARGFOLDER$FILENAME" "$PFAD/$FILENAME"
            	fi
            fi
   		done
   	fi
   	sleep 2
done

Thatīs ok without white spaces. basename/dirname doesnīt work with white space. My experiments with sed wasnīt successfully.
Can someone help me?
Thank you
tubian.
# 2  
Old 05-07-2009
Putting speech marks around $i as below:
Code:
FILENAME=`basename "${i}"`
PFAD=`dirname "${i}"`

should prevent the white spaces in $i causing problems.
# 3  
Old 05-08-2009
Thank you for your answer!
Iīd tried this, but no success. Smilie
"ls: /Volumes/Movies/FCP/Capture: No such file or directory
ls: /Volumes/Movies/FCP/Scratch: No such file or directory"

Do you have another solution?

Thank you,

tubian
# 4  
Old 05-08-2009
use a while read loop instead of a for loop with your find command
Code:
find ..... | while read FILE
do
 ....
done

# 5  
Old 05-09-2009
Thank you very much, your solution works very fine!

tubian
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix remove white spaces/tabs before & after pattern

Hi All, I wanted to know is there any way we can remove white spaces/tabs before & after some pattern { eg. before & after "," }. Please find below sample data below, Sat Jul 23 16:10:03 EDT 2011 , 12345678 , PROD , xyz_2345677 , testuuyt , ... (3 Replies)
Discussion started by: gr8_usk
3 Replies

2. Shell Programming and Scripting

Leading white spaces

Hi, I am having problem in deleting the leading spaces:- cat x.csv baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played $ nawk 'BEGIN{FS=","}!a... (2 Replies)
Discussion started by: scripter12
2 Replies

3. Shell Programming and Scripting

find -exec directories with spaces

All, I have a cleanup script that removes directories and all contents underneath, but I am having issues with directories with spaces. This is the command I am currently running, how can I get it to work with directories with spaces? find /path -mindepth 3 -type d -exec rm -rf {} \; (29 Replies)
Discussion started by: markdjones82
29 Replies

4. UNIX for Dummies Questions & Answers

Problems with find & -size

Hi I am trying to find files over a size given by the user. this is what I have so far echo "Enter a pathname to check (example = /home/jsk1gcc/testwork): " read input echo "Enter a the size (examples = 100k, 10M, 1G): " read size find $input -size +$size echo echo "Hit the Enter... (2 Replies)
Discussion started by: AngelFlesh
2 Replies

5. Shell Programming and Scripting

Script to find folders with spaces and end of files and directories

Hi I need a script that can search through a set of directories and can locate any file or directory that has a space at the end Filename(space) Foldername(space) I then need to remove that space within the script Hope someone can help thanks in advance Treds (8 Replies)
Discussion started by: treds
8 Replies

6. Shell Programming and Scripting

Two or more white spaces in string

Hi, Can anybody suggest me how to combine two strings with two or more white spaces and assign it to a variable? E.g. first=HAI second=HELLO third="$first $second" # appending strings with more than one white spaces echo $third this would print HAI HELLO Output appears... (2 Replies)
Discussion started by: harish_oty
2 Replies

7. Shell Programming and Scripting

trimming white spaces

I have a variable that calls in a string from txt file. Problem is the string comes with an abundance of white spaces trailing it. Is there any easy way to trim the tailing white spaces off at the end? Thanks in advance. (9 Replies)
Discussion started by: briskbaby
9 Replies

8. Shell Programming and Scripting

delete white spaces

hi all... i have the next question: i have a flat file with a lot of records (lines). Each record has 10 fields, which are separated by pipe (|). My problem is what sometimes, in the first record, there are white spaces (no values, nothing) in the beginning of the record, like this: ws ws... (2 Replies)
Discussion started by: DebianJ
2 Replies

9. UNIX for Dummies Questions & Answers

deleting white spaces

How would I delete white spaces in a specified file? Also, I'd like to know what command I would use to take something off a regular expression, and put it onto another. ie. . . . expression1 <take_off> . . . expression2 (put here) . . . Any help would be great, thanks! (10 Replies)
Discussion started by: cary530
10 Replies
Login or Register to Ask a Question