gpt4 book ai didi

bash - 删除所有以小写字符开头的行

转载 作者:行者123 更新时间:2023-12-02 04:33:34 25 4
gpt4 key购买 nike

如何从文件中删除以小写字符或标点符号开头的所有行?

A bamboo forest is located towards the ruins.
a banana .
aban Bajramovi was a Serbian-Romani musician.
Abancay is a city in southern-central Peru.
! a ban is the strictest punishment.

我希望我的输出是:

A bamboo forest is located towards the ruins.
Abancay is a city in southern-central Peru.

我正在尝试 sed

sed 's/^[A-Z]/d' input 

但没有得到想要的结果,有什么建议吗?

最佳答案

试试这个:

sed '/^[a-z[:punct:]]/d' file 

或者您可以按照 @glennjackman 的建议对两者使用字符类在评论中:

sed '/^[[:lower:][:punct:]]/d' file 

$ cat file
A bamboo forest is located towards the ruins.
a banana .
aban Bajramovi was a Serbian-Romani musician.
Abancay is a city in southern-central Peru.
! a ban is the strictest punishment.

$ sed '/^[a-z[:punct:]]/d' file
A bamboo forest is located towards the ruins.
Abancay is a city in southern-central Peru.

$ sed '/^[[:lower:][:punct:]]/d' file
A bamboo forest is located towards the ruins.
Abancay is a city in southern-central Peru.

关于bash - 删除所有以小写字符开头的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22491064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com