下面的python需求文件定义了超过500个包,每个包都有一个“
==
”,后面跟着version
字符串。
# comment string
python_package_a == 1.2.3
# some text
python_package_b == 2.3.4
# test bar
hello == 0.1.2
# many other packages (more than 500 packages)
other_500_packages == x.y.z
我想使用
bash sed
从需求文件中删除所有版本。
这是预期的输出:
# comment string
python_package_a ==
# some text
python_package_b ==
# test bar
hello ==
# many other packages (more than 500 packages)
other_500_packages ==
如何编写“
sed
”命令以仅从所有包行中删除“version
”?
我知道如何使用 sed 搜索替换整行,但我不知道如何保留“==”之前的所有字符串
你不必“保留”,只需匹配该行的一部分即可。只需匹配
==
,然后匹配该行的其余部分。然后将其替换为==
。
sed 's/==.*/==/'