문제

(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