Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to comment out all lines containing "dlclose" for each file in the current directory and any sub-directories (recursively). This is my best guess so far given what I was able to find out from various guides.

grep -lIR "dlclose" . | grep -v ".svn" | sed -i 's/.*dlclose.*/\/\/&/g'

The two greps successfully find all files I want changed, but sed claims an unterminated s command.

share|improve this question
    
Use a different delimiter with sed and you won't need to escape the slashes. That will make it easier to read. sed 's|.*dlclose.*|//&|g' –  Dennis Williamson Aug 12 '10 at 3:48

1 Answer 1

You are attempting to edit in place (-i option) the STDIN.

Remove -i option, it is useless.

Note:

You can speed up the command a lot avoiding the second grep, excluding at the root the unnecessary directories

Try

grep -lIR --exclude-dir=.svn "dlclose" . | xargs sed -i bak 's/.*dlclose.*/\/\/&/g'  

or

for f in $(grep -lIR --exclude-dir=.svn "dlclose" .)
do
   sed -i bak 's/.*dlclose.*/\/\/&/g' $f
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.