Monday, January 25, 2010

Remove Control characters from unix file

One way is to use the tr command to delete the control characters using octal values. Since the octal values of ^M, ^H, ^G are 015, 010, 007 respectively, this command deletes the 3 control characters:

tr -d '\015\010\007' <> new.data.file

If you need the value of other control characters, but do not have an ASCII chart, use this method to deterine the value: from within vi and in an edit mode, press control-v and then press the control character. Save the file and perform an od -b command on the file. This displays the octal value.

No comments:

Post a Comment