gpt4 book ai didi

python - 如何删除其中包含特殊字符的行

转载 作者:IT王子 更新时间:2023-10-29 00:52:26 27 4
gpt4 key购买 nike

我有一个很大的文本文件,里面有很多特殊字符,比如 "$!@%#$/"还有很多,如果文本文件中有任何特殊字符,我想删除该行那条线。我想保留的唯一字符是 a-z 和 A-Z。

如果这是文件...

!Somejunk)(^%
)%(&_
this
my_file
is
*(%%$
the
they're
file

那么剩下的就只有...

this
is
the
file

使用 linux 命令行工具、bash 脚本或 python 脚本的解决方案会更好,但任何可行的都行!

最佳答案

$ grep '^[[:alpha:]]\+$' << EOF
> !Somejunk)(^%
> )%(&_
> this
> my_file
> is
> *(%%$
> the
> they're
> file
> EOF
this
is
the
file

关于python - 如何删除其中包含特殊字符的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7937042/

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