如何使用sed删除版本。

huangapple go评论67阅读模式
英文:

How to remove versions with sed

问题

以下是翻译好的部分:

以下的Python元数据文件包含以下所需的库:

Requires-Python: >=3
Requires-Dist: hello (~=0.1.1)
Requires-Dist: bar (~=1.14)
Requires-Dist: hello-world (~=1.10)
Requires-Dist: test (~=1.1) ; python_version < "3.4"
Requires-Dist: test-bar

如何使用单个sed bash命令来搜索并替换所有所需库的所有版本?

以下是预期输出:

Requires-Python: >=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar

英文:

The following python metadata file contains the following required libraries:

Requires-Python: &gt;=3
Requires-Dist: hello (~=0.1.1)
Requires-Dist: bar (~=1.14)
Requires-Dist: hello-world (~=1.10)
Requires-Dist: test (~=1.1) ; python_version &lt; &quot;3.4&quot;
Requires-Dist: test-bar
...

How to use a single sed bash command to search and replace all versions from all required libraries?

Here is the expected output:

Requires-Python: &gt;=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar
...

答案1

得分: 2

使用 GNU sed

sed &#39;s/(.*//&#39; file

输出:

Requires-Python: &gt;=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar

解释:

(.*    : 匹配从 &#39;(&#39; 到行尾的模式
//      : 清空或删除匹配的模式
英文:

Using GNU sed:

sed &#39;s/(.*//&#39; file

Output:

Requires-Python: &gt;=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar

Explanation:

(.*    : to match the pattern starting from &#39;(&#39; to the end of the line
//      : to empty or to remove the matched pattern

huangapple
  • 本文由 发表于 2023年6月6日 11:20:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定