Change a string in a file with sed?

别说谁变了你拦得住时间么 提交于 2019-12-06 02:48:54

You don't need the grep.

sed -i '/Version/s/3\.1\.0\.2-1/3.1.0.2/' <files>

You want to use the "-i" switch to sed for "edit file [I]n place."

See sed man page: http://unixhelp.ed.ac.uk/CGI/man-cgi?sed

The name sed literally comes from "Stream EDitor" - the behavior you're seeing is the way it was designed. When you say:

sed 'some commands' file

it reads the file, executes the commands and prints the result - it doesn't save it back to the file (although some versions of sed have some options to tell it to do that). You probably want to do this:

sed 'some commands' file > newfile

Then verify that newfile is correct, and then mv newfile file. If you're absolutely certain your edit script is correct, and you can deal with the consequences of overwriting your file with wrong data if they're not, then you might consider using the in-place editing flags, but it's generally safer to save to a temporary file so you can test/validate.

You have a typo, the last dot should be a dash, try this:

sed 's/3.1.0.2-1/3.1.0.2-2/'
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!