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,
o*v
2 楼
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 的大作中提到】
o*v
4 楼
^m=回国 global, try
o*v
5 楼
是回车,不好意思【 在 ooev (我所说的一切都可作为灌水证供) 的大作中提到: 】
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
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?
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. :(
【在 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. :(
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"
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,
j*y
12 楼
Thanks, this works perfectly, too. :)
【在 c****s 的大作中提到】 : sed -i -e "s/12345/54321/g" filename
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,
a*r
14 楼
o ft 已经有人回了。。
【在 c****s 的大作中提到】 : sed -i -e "s/12345/54321/g" filename