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

标签 python linux bash

我有一个很大的文本文件,里面有很多特殊字符,比如 "$!@%#$/"还有很多,如果文本文件中有任何特殊字符,我想删除该行那条线。我想保留的唯一字符是 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/

相关文章:

python - 从 boost::python::object 列表中获取单个元素,用于 python 例程

python - 以表格格式漂亮地打印列表

linux - Linux 中 KLIPS 和 Netkey IPSEC 堆栈的区别

linux - 如何使日期命令与自定义指定日期相关?

linux - 通过从文件中的每一行获取两个参数来循环的 Shell(bash) 脚本

ruby-on-rails - Dotenv 多行变量

linux - 从文件中删除连续包含 4 个或更多相同字符的行

Linux 上的 Python Smtp SSL 版本错误

python - 如何用虚线绘制渐近线?

linux - bash:一次获取多个数组元素的更简单方法?