How to remove all special characters in Linux text

后端 未结 4 1742
囚心锁ツ
囚心锁ツ 2020-12-14 20:51

How to remove the special characters shown as blue color in the picture 1 like: ^M, ^A, ^@, ^[. In my understanding, ^M is a windows newline character, I can use sed

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 21:01

    To ensure that the command works with limited scope in Sed, force use of the "C" (POSIX) character classifications to avoid unpredictable behavior with non-ASCII characters:

    LC_ALL=C sed 's/[^[:blank:][:print:]]//g' file.txt
    

提交回复
热议问题