Reputation: 53
I am trying to use the find and sed commands in Linux to do the following:
I have been using: this, this and this as research references.
My current command that is not working is:
find . -name "*.cbf" -print0 | xargs -0 sed -i '' -e 's/# change the header/# change the header to something/g'
The error I get is: sed: can't read : No such file or directory
I have tried the command both above the directory with the .cbf files and actually in the directory.
Can someone please help me with what I am doing wrong. I simply wish to edit a line in all .cbf files in subdirectories from where I am sitting.
Thanks in advance
Upvotes: 1
Views: 403
Reputation: 3608
Your command actually works. The error you see is related to -i ''
part which seems wrong. The option to -i
should be used to provide a suffix for backups when doing an in-place edit, and should be given without any space: -i.bak
.
If you don't need backups at all, just don't give any extra option after -i
. In your case sed
is thinking that extra ''
is a filename and is actually trying to open it (quote from strace
output):
4000 open("", O_RDONLY) = -1 ENOENT (No such file or directory)
So, the correct command should not have ''
after -i
.
Upvotes: 2
Reputation: 784888
Try this find
/sed
command:
find . -name "*.cbf" -print0 | xargs -0 -I {} sed -i.bak 's/# change the header/# change the header to something/g' {}
Upvotes: 2