M
Marc Girod
Hello,
I was asked a way to strip control characters from a text file.
Soon, it became clear that newlines must be kept, as well as
(probably) tabs.
The context was however unix only.
Inspired in part by recent posts in this group, I came up with the
following one-liner:
perl -pi2 -e 'BEGIN{$rep{chr($_)}=q() for 0..31,127;$rep{chr(10)}=chr
(10)}s/([[:cntrl:]])/$rep{$1}/g' /tmp/fff
....assuming the file was /tmp/fff, and keeping a backup of it.
I would now humbly turn to you for critique and improvements.
Thanks,
marc
I was asked a way to strip control characters from a text file.
Soon, it became clear that newlines must be kept, as well as
(probably) tabs.
The context was however unix only.
Inspired in part by recent posts in this group, I came up with the
following one-liner:
perl -pi2 -e 'BEGIN{$rep{chr($_)}=q() for 0..31,127;$rep{chr(10)}=chr
(10)}s/([[:cntrl:]])/$rep{$1}/g' /tmp/fff
....assuming the file was /tmp/fff, and keeping a backup of it.
I would now humbly turn to you for critique and improvements.
Thanks,
marc