Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

linux - Search and replace with sed when dots and underscores are present

How do I replace foo. with foo_ with sed simply running

sed 's/foo./foo_/g' file.php

doesn't work. Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Escape the .:

sed 's/foo./foo_/g' file.php

Example:

~$ cat test.txt 
foo.bar
~$ sed 's/foo./foo_/g' test.txt 
foo_bar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...