M*****a 发帖数: 2054 | 1 WRITE a script for searching a text john in entire directories (one
directory can contain another directory) and replace it with TOM |
M*****a 发帖数: 2054 | 2 我知道没有子目录的话,sed足够了
但是有子目录,咋办啊
【在 M*****a 的大作中提到】 : WRITE a script for searching a text john in entire directories (one : directory can contain another directory) and replace it with TOM
|
m******t 发帖数: 2416 | 3
Untested but something like this:
find . -type f -exec sed -i 's/john/TOM/g' \{} \;
or
find . -type f | xargs sed -i 's/john/TOM/g'
【在 M*****a 的大作中提到】 : 我知道没有子目录的话,sed足够了 : 但是有子目录,咋办啊
|
b******n 发帖数: 592 | 4 If it is a real task, I strongly recommend you do not use in-place sed.
Always keep the original file.
【在 m******t 的大作中提到】 : : Untested but something like this: : find . -type f -exec sed -i 's/john/TOM/g' \{} \; : or : find . -type f | xargs sed -i 's/john/TOM/g'
|
m******t 发帖数: 2416 | 5
Well make a copy first, and _then_ use sed -i. 8-)
【在 b******n 的大作中提到】 : If it is a real task, I strongly recommend you do not use in-place sed. : Always keep the original file.
|
b******n 发帖数: 592 | 6 of course..just some tip for the guy asking questions.
or just sed file.org > file.mod
【在 m******t 的大作中提到】 : : Well make a copy first, and _then_ use sed -i. 8-)
|
M*****a 发帖数: 2054 | 7 有道理!
把find出来所有的文件然后用pipe传给sed
【在 m******t 的大作中提到】 : : Well make a copy first, and _then_ use sed -i. 8-)
|