質問

(I'm sure this has been asked before, but I can only find somewhat-similar questions.)

I have bunch of files, some of which contain the string "foobar". I would like to replace, in each of those files, the occurrences of "foobar" with "baz" - in those files, not in new files or streamed anywhere.

I'd like to specify the filenames on the command-line, i.e.

[me@myhost:/$] magic_replace "foobar" "baz" file1 file2 file3 etc
役に立ちましたか?

解決 2

Try this:

sed -i -e 's/foo/baz/g' file1 file2

or this:

for file in $(echo file1 file2); do
    sed -i -e 's/foo/baz/g' $file
done

The first one should work if sed accepts multiple input files, check it.

他のヒント

use sed.

sed -i 's/foobar/baz/g' file1 file2 file3 etc
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top