avatar
j*y
1
If I want to replace the string "12345" (in the file test.c) with "54321", how
to make it with shell script or in vi?
thanks,
avatar
o*v
2
avatar
j*y
3
What's the effect of ^m?
Btw, the file contains more than one instance of the string "12345". Still the
same script in vi?
thanks,

how

【在 o**v 的大作中提到】

avatar
o*v
4
^m=回国
global, try
avatar
o*v
5
是回车,不好意思【 在 ooev (我所说的一切都可作为灌水证供) 的大作中提到: 】
avatar
j*y
6

It failed.
I opened test.c with vi (vi test.c), and type ":s/12345/54321/g^m", right?

【在 o**v 的大作中提到】
: ^m=回国
: global, try

avatar
t*y
7
ft,just type":s/12345/54321/g"

【在 j***y 的大作中提到】
:
: It failed.
: I opened test.c with vi (vi test.c), and type ":s/12345/54321/g^m", right?

avatar
j*y
8

still the error: Substitute pattern match failed.
But I can confirm the string's existence by using "/12345" to find it.
Another finding is: when i move the cursor to the beginning of string 12345,
and type the above command, it can be replaced. But even in this case, it
can't be replaced globally. only change one instance. :(

【在 t*******y 的大作中提到】
: ft,just type":s/12345/54321/g"
avatar
t*y
9
type":% s/12345/54321/g"

【在 j***y 的大作中提到】
:
: still the error: Substitute pattern match failed.
: But I can confirm the string's existence by using "/12345" to find it.
: Another finding is: when i move the cursor to the beginning of string 12345,
: and type the above command, it can be replaced. But even in this case, it
: can't be replaced globally. only change one instance. :(

avatar
j*y
10

Thanks, it works finally.
A minor correction: there shouldn't be space character between % and s.
So my working command is ":%s/12345/54321/g".
Thanks again.

【在 t*******y 的大作中提到】
: type":% s/12345/54321/g"
avatar
c*s
11
sed -i -e "s/12345/54321/g" filename

【在 j***y 的大作中提到】
: If I want to replace the string "12345" (in the file test.c) with "54321", how
: to make it with shell script or in vi?
: thanks,

avatar
j*y
12

Thanks, this works perfectly, too. :)

【在 c****s 的大作中提到】
: sed -i -e "s/12345/54321/g" filename
avatar
a*r
13
sed -e "s/12345/54321/g" file

【在 j***y 的大作中提到】
: If I want to replace the string "12345" (in the file test.c) with "54321", how
: to make it with shell script or in vi?
: thanks,

avatar
a*r
14
o ft 已经有人回了。。

【在 c****s 的大作中提到】
: sed -i -e "s/12345/54321/g" filename
avatar
c*s
15
lol, 还需要-i吧,否则只是输出到stdout:)

【在 a***r 的大作中提到】
: sed -e "s/12345/54321/g" file
avatar
a*r
16
oh~ 土了。。我一直都是用重定向 然后rename

【在 c****s 的大作中提到】
: lol, 还需要-i吧,否则只是输出到stdout:)
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。