bash - 如何在bash中删除文件中除特定字符之外的所有内容?

标签 bash tr

我有一个包含字符串的文件:

aa12bb34cc z23abZY
123 87aab
6667771

所以我希望输出是:

aabbcc ab aab

使用 tr 我获得了这个字符串作为输出:

aa bb cc ab aab

有什么想法吗?

最佳答案

我建议使用 GNU tr:

tr -cd 'abc ' < file

输出:

aabbcc ab aab

-d: delete all a, b, c and white spaces

-c use the complement. Delete everything but a, b, c and white spaces.

关于bash - 如何在bash中删除文件中除特定字符之外的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41088117/

相关文章:

linux:将参数传递给 .bashrc 文件

bash - 找到文件夹并 cd 进去

linux - 在 Bash 中反转二进制数

linux - 将/proc/1/environ 转换为变量脚本

linux - *nix 方法在 ',' 之后乘以行

bash - 'cd $_' 是什么意思?

linux - 如何在 shell 脚本中动态生成新的变量名?

bash - 三个变量的大括号范围扩展

bash - 打印当前路径的一部分

Bash:用换行符替换 "",使用 sed 或 tr