rob*_*ntw 5 command-line sed string line-editor replace
我有一个文本文件,其中有一些与此类似的内容:
# General information about the project.
project = u'Py6S'
copyright = u'2012, Robin Wilson'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.5'
# The full version, including alpha/beta/rc tags.
release = '0.5'
Run Code Online (Sandbox Code Playgroud)
我想version = '0.5'用version = X其中 X 是给脚本的命令行参数替换该行,然后对该release =行执行相同的操作。
我可以调用一个简单的命令来进行这种替换吗?我已经研究sed了一下,但似乎 sed 中的全局替换需要我搜索version = '0.5',但我真正想要搜索的只是一行开头version =- 因为我不知道当我运行脚本!
有任何想法吗?
sed -i "/^version =/s/'[^']*'/'NEW_VERSION_IS_HERE'/" your_file
Run Code Online (Sandbox Code Playgroud)