英文:
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: >=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
...
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: >=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar
...
答案1
得分: 2
使用 GNU
sed
:
sed 's/(.*//' file
输出:
Requires-Python: >=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar
解释:
(.* : 匹配从 '(' 到行尾的模式
// : 清空或删除匹配的模式
英文:
Using GNU
sed
:
sed 's/(.*//' file
Output:
Requires-Python: >=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 '(' to the end of the line
// : to empty or to remove the matched pattern
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论