如何从 bash 中的文件中删除特定字符以外的所有内容?

how to delete everything except specific characters from a file in bash?

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

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.