Trying to remove non-printable charaters(junk values) from a UNIX file

前端 未结 3 428
囚心锁ツ
囚心锁ツ 2021-01-18 13:40

I am trying to remove non-printable character (for e.g. ^@) from records in my file. Since the volume to records is too big in the file using cat is not an opti

3条回答
  •  广开言路
    2021-01-18 13:41

    Perhaps you could go with the complement of [:print:], which contains all printable characters:

    tr -cd '[:print:]' < file > newfile
    

    If your version of tr doesn't support multi-byte characters (it seems that many don't), this works for me with GNU sed (with UTF-8 locale settings):

    sed 's/[^[:print:]]//g' file
    

提交回复
热议问题