sed: can't read book/ : No such file or direct

2019-03-06 17:12发布

问题:

I ran the following one line code on Red Hat Enterprise Linux Server release 6.6 (Santiago)

 grep -rl 'room' book/ | xargs sed -i 's/room/equipment/g'

And I got the following message

sed: can't read book/
book/del_entry_ajax.php: No such file or directory

Acutally I can run

grep -rl 'room' book/del_entry_ajax.php | xargs sed -i 's/room/equipment/g'

successfully and then run the first command again, I got

sed: can't read book/
: No such file or directory

Why is that and how can I fix it?

回答1:

The GNU guys really messed up when they gave grep an option to find files. There is a perfectly good UNIX tool to find files and it has a perfectly obvious name - find. Try this:

find book -type f -print0 | xargs -0 sed -i 's/room/equipment/g'


标签: replace sed grep