Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to run a command to remove require_once from php files from here (code below), but I am getting the error:

sed: can't read -: No such file or directory

I am in the correct folder; what's the problem?

find . -name '*.php' -not -wholename '*/Loader/Autoloader.php' \
  -not -wholename '*/Application.php' -print0 | \
  xargs -0 sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

Update:

If I run:

find . -name '*.php' -not -wholename '*/Loader/Autoloader.php' \
  -not -wholename '*/Application.php' -print0

I get:

find: invalid predicate `-wholename'

I tried this and it returned a list of all the files:

find . -name '*.php' -not -name '*/Loader/Autoloader.php' \
  -not -name '*/Application.php' -print0

But then changing the original to reflect this:

find . -name '*.php' -not -name '*/Loader/Autoloader.php' \
  -not -name '*/Application.php' -print0 | \ xargs -0 sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

Gives the error:

-bash: xargs: command not found

FYI, I'm running sed version 4.1.2 and I'm a bit a lost in the command line already, so please explain answers

share|improve this question
2  
Works for me. Replace "xargs -0 sed" with "xargs -0 echo sed". What's the output of that? –  EricSchaefer Nov 11 '10 at 16:18
    
Can't get past the -bash: xargs: command not found error –  Ashley Nov 11 '10 at 17:36
    
The -bash: xargs: command not found error is because of the backslash immediately before xargs. If you remove the backslash or if there's a newline after the backslash, it should work. –  Dennis Williamson Nov 11 '10 at 22:31
    
@ Dennis, make that an answer and it's all yours. Worked a charm –  Ashley Nov 11 '10 at 22:42
1  
Why are you piping find to xargs can't -exec do it for you? maybe read this question –  xenoterracide Nov 12 '10 at 13:58

4 Answers 4

The error seems to indicate that sed tries to read from stdin. Have you tried just the find part to see if it returns any file?

share|improve this answer
1  
If I modify the -wholename to -name it works (without the rest of the code) –  Ashley Nov 11 '10 at 17:37

Your second invocation doesn't make any sense, why the "\ " before the xarsg? You try to call a program called " xargs", and bash tells you it can't find it (note the double blank after the colon), which is hardly surprising.

To get rid of the error case where sed hangs when xargs returns zero files (because it's trying to read from stdin when there are no command line arguments), you should add -r to your xargs arguments.

share|improve this answer
    
It's from the Zend Framework docs, I didn't write it (and wouldn't know how) –  Ashley Nov 12 '10 at 21:41

What version of sed do you have? POSIX sed doesn't understand double-dash options, neither does minised, but GNU sed does.

For something more portable (and IMO nicer), try sed -i '/require_once/s![[:space:]]*!&// !'.

share|improve this answer
    
I don't think sed -i is any more portable than sed --in-place, it's a GNU extension anyway. FreeBSD also has it, but the suffix argument is compulsory, to you have to write sed -i .bak or sed -i ''. –  Gilles Nov 11 '10 at 16:42
    
sed v4.1.2, please see question for update –  Ashley Nov 11 '10 at 17:35

I prefer perl -pi.bak for these sorts of cases.

FMTYEWTK at http://www.perl.com/pub/2004/10/14/file_editing.html

(FMTYEWTK stands for Far More Than You Ever Wanted To Know)

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.