making find/sed to include directory names with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting making find/sed to include directory names with spaces
# 1  
Old 05-13-2012
making find/sed to include directory names with spaces

how can i make find/sed to include directory names with spaces

the command is like this
Code:
for i in `find wp-content/themes -type f -print0 | xargs -0 grep -l
-iE 'e'`;do sed -i -e 's/word1/word2/gI' "$i";done

but it skips one directory names with spaces
Code:
sed: can't read ./Nova: No such file or directory
sed: can't read pasta/font/bougan_black_ssi_bold-webfont.eot: No such
file or directory
sed: can't read ./Nova: No such file or directory
sed: can't read pasta/font/bougan_black_ssi_bold-webfont.svg: No such
file or directory
sed: can't read ./Nova: No such file or directory
sed: can't read pasta/font/alternate_gothic_no2_bt-webfont.eot: No
such file or directory
sed: can't read ./Nova: No such file or directory
sed: can't read pasta/font/alternate_gothic_no2_bt-webfont.svg: No
such file or directory
sed: can't read ./Nova: No such file or directory
sed: can't read pasta/font/bougan_black_ssi_bold-webfont.woff: No such
file or directory
sed: can't read ./Nova: No such file or directory
sed: can't read pasta/font/agentcondb_normal-webfont.eot: No such file
or directory


thanks!
# 2  
Old 05-13-2012
Try a construction like:
Code:
find wp-content/themes -type f | 
while read i
do
  ...   "$i"
done

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 05-13-2012
EDIT: Please read on. There is nothing useful in this post...

Last edited by mirni; 05-14-2012 at 02:51 AM..
This User Gave Thanks to mirni For This Post:
# 4  
Old 05-13-2012
thanks

when i just quote the find part, it says

File name too long



also another question, if i use a variable like
$word1, $word2

does that allow for words that have a slash?
like if word1 is domain.com/something
will it work if i use that?

thanks

---------- Post updated at 09:57 PM ---------- Previous update was at 09:11 PM ----------

also do you know how to exclude a filename? i want to exclude the images like .gif, .png, .gif and all cases of it like .GIF, .PNG, etc.

this doesn't work

Code:
find /home/$user/public_html -wholename '*/albums/*' -prune -o -wholename '*/uploads/*' -prune -o -type f -not -name ".jpg" -not -name ".gif" -not -name ".png" -print |
while read FILE
  do
  echo "FILE is $FILE"
  sed -i -e 's/$BEFORE/$AFTER/gI' "$FILE";
done


thanks!
# 5  
Old 05-14-2012
Oops, please disregard my previous post. I spaced out -- using quotes in the for loop would treat the whole output of find as one thing: the loop would run only once, and it would contain everything. Sorry for misinformation...

Yes, certainly, forward slash is perfectly valid character in variables.
But not if you are doing something like:
Code:
sed "s/$word/$other/" file

and $word or $other contain slashes, sed will be confused. In that case, you can use some other character as delimiter for 's' command, like:
Code:
sed "s!$word!$other!" file

or
Code:
sed "s+$word+$other+" file

To exlude the extensions, do:
Code:
 -not \( -name "*.[gG][iI][fF]" -o -name "*.[pP][nN][gG]" \)

or
Code:
 -not -name "*.[gG][iI][fF]" -a -not -name "*.[pP][nN][gG]"

-o stands for OR, -a for AND, parens have to escaped, otherwise shell interprets them as "run in subshell"

Last edited by mirni; 05-14-2012 at 02:52 AM..
This User Gave Thanks to mirni For This Post:
# 6  
Old 05-16-2012
thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Problem with shell script while spaces encountered in directory names

Hi, I am having issues with the jar -tf command when I put in the shell script. The command runs fine from the command line as shown below. # jar -tf "./VirtualBox Dropped Files/2016-04-17T20:58:49.129139000Z/hive-exec-0.8.1.jar" But when I put in a shell script(shown below) and the... (10 Replies)
Discussion started by: vinoo128
10 Replies

2. Shell Programming and Scripting

Find Command Include Sub Directory

This script writes the output files to FILES but I don't want to exclude all directories from ABC_CHQ and LYS_ADV, I want to include one sub directory name process which is under ABC_CHQ and LYS_ADV in the search. Right now its excluding everything from prune directories such as ABC_CHQ, LYS_ADV... (10 Replies)
Discussion started by: John William
10 Replies

3. UNIX for Dummies Questions & Answers

Need help with sed replace script to include spaces

I've got a sed shell script I've been using for quite a while to do batch find/replace operations on .xml files containing various types of text entries. This is the script I use: #!/bin/bash while read text_old text_new; do sed_script+="s/$text_old/$text_new/g;" done < trans_old_to_new... (9 Replies)
Discussion started by: Agreppa
9 Replies

4. Shell Programming and Scripting

How to find all files which has names in uppercase in a directory

i want to display all the files which has their names in the Uppercase in a particular directory...guide.. (6 Replies)
Discussion started by: sheelsadan
6 Replies

5. Shell Programming and Scripting

How to find empty files in a directory and write their file names in a text?

I need to find empty files in a directory and write them into a text file. Directory will contain old files as well, i need to get the empty files for the last one hour only. (1 Reply)
Discussion started by: vel4ever
1 Replies

6. UNIX for Dummies Questions & Answers

find the file names having specified pattern at specified position in the current directory

I would need a command for finding first 15000 of the file names whose 25th postion is 5 in the current directory alone. I do have this painful command find . -name '5*' | head -15000 | cut -c3- please refine this. Of course the above command also searches in the sub directories... (3 Replies)
Discussion started by: vk39221
3 Replies

7. Shell Programming and Scripting

Find Directory from array of file names with paths

I have a script that generates a variable with the location of a file and its complete path. What i want to do is to "cd" to the directory where that file is located using the path name of the file. GIS has absolutely failed me. For example when i run my script it generates a variable called... (1 Reply)
Discussion started by: Knome
1 Replies

8. Shell Programming and Scripting

find the length of file names in a directory?

Hi, how can find length of file names in a directory. Examp: I have a directory with name "d1". directory: d1 files: aaa.log bbb.log abcd.log abcdef.log I wold like out put like: file name legnth aaa.log 3 bbb.log 3 abcd.log 4 abcdef.log 5 (5 Replies)
Discussion started by: koti_rama
5 Replies

9. OS X (Apple)

changing multiple directory names w/ sed

ive looked and couldnt find an answer... can someone tell me how i can replace spaces and characters with an "_" on multiple folders? thanx muchly. (1 Reply)
Discussion started by: RahJiggah
1 Replies

10. Shell Programming and Scripting

Directory names that contain spaces and other suggestions?

The script below was written to select files and convert a particular string to something other and replace that file. However, I came across some issues with filenames that contain spaces, any suggestions to get around this? Any other suggestions that may apply to this code would also be... (5 Replies)
Discussion started by: Shakey21
5 Replies
Login or Register to Ask a Question