avatar
p*u
1
replace an old string with a new string in a lot of file, please tell me the
command name and necessary arguments. thank you very much!
avatar
f*n
2
vi: 进入command状态, vi左下角出现“:”
<:>oldstringnewstring
其中的 <> 是为了方便阅读用的, 实际操作时去掉。

【在 p*u 的大作中提到】
: replace an old string with a new string in a lot of file, please tell me the
: command name and necessary arguments. thank you very much!

avatar
c*e
3

你可以 man 一下 sed,这个命令很有用
一般情况下,可以用:
cat source_filename | sed -e s/"sourceString"/"targetString"/g >
target_filename
如果多个文件,可以用 for 循环。

【在 p*u 的大作中提到】
: replace an old string with a new string in a lot of file, please tell me the
: command name and necessary arguments. thank you very much!

avatar
s*s
4

an alternative way: :%s/oldstring/newstring/g
the

【在 f****n 的大作中提到】
: vi: 进入command状态, vi左下角出现“:”
: <:>oldstringnewstring
: 其中的 <> 是为了方便阅读用的, 实际操作时去掉。

avatar
p*r
5
#!/bin/sh
# This is a simple script that replace string in a file.
# No argument checking.
str_orig=$1
str_new=$2
shift
shift
for i in $*; do
sed -e s/$str_orig/$str_new/g $i > /tmp/$i.$$
mv /tmp/$i.$$ $i
done
exit 0

【在 p*u 的大作中提到】
: replace an old string with a new string in a lot of file, please tell me the
: command name and necessary arguments. thank you very much!

avatar
k*n
6
the simplest way to do this is:
find . -name "*.c" -exec vi -c "1,$ s/old_string/new_string/g" -c "wq" {} \;
will replace all old string with new string in all .c files

【在 p*********r 的大作中提到】
: #!/bin/sh
: # This is a simple script that replace string in a file.
: # No argument checking.
: str_orig=$1
: str_new=$2
: shift
: shift
: for i in $*; do
: sed -e s/$str_orig/$str_new/g $i > /tmp/$i.$$
: mv /tmp/$i.$$ $i

avatar
q*t
7
cool!

【在 k*****n 的大作中提到】
: the simplest way to do this is:
: find . -name "*.c" -exec vi -c "1,$ s/old_string/new_string/g" -c "wq" {} \;
: will replace all old string with new string in all .c files

avatar
c*e
8
A more effective way would be a one line comand:
for file in *.c; do sed -e s/"old_string"/"new_string"/g $file | cat >
$file;done

the

【在 k*****n 的大作中提到】
: the simplest way to do this is:
: find . -name "*.c" -exec vi -c "1,$ s/old_string/new_string/g" -c "wq" {} \;
: will replace all old string with new string in all .c files

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。