File has control Z( ^Z) characters in them. I tried
sed 's/^Z//g' file_name but not working. Even tried perl script but not removing them. Please let me know if there is way to remove this character.
The control character produced by Ctrl+Z is
\032 in octal. This can be deleted by
tr -d '\032' <file >newfile
This deletes the characters anywhere in the file and creates a new file called
newfile with the modified contents.
sed command does not work as the expression
^Z would match a
Z character at the start of the line. The
^ anchors the rest of the expression at the start of the line.
You can match Ctrl+Z using
\d plus the decimal code of the character (in this case 26).
sed 's/\d26//g' < file > newfile
A "posix" alternative (in bash) could be something like:
sed $( echo 's/@//g' | tr '@' '\032' ) < file > newfile
The tr will replace '@' in regex with the carachter Ctrl+Z (which code is 32 in octal).
$ sed 's/\^Z//g' filename
NOTE: Special characters should be escaped with '\'.