Removing Control Characters from a File

Instead of using the predefined [:cntrl:] set, which as you observed includes \n and \r, just list (in octal) the control characters you want to get rid of:

$ tr -d '\000-\011\013\014\016-\037' < file.txt > newfile.txt

Leave a Comment