Friday, December 12, 2008

Special characters in shell

If you seeing some special characters using less, then you are in the right place. Bumped into this problem last evening, when i was trying to parse an utf8 coded html. You may write special characters in shell using (ctrl+v) (ctrl+x), where x is your desired character.
When you use for example ^M in bash script - its not recognized, even if you edit it vith vi. I found the solution in perl forum.

grep ^D
(type ctrl-V ctrl-D)
perl -ne 'print if /\cD/'


Use \cx notation in shell scripting, where x is your desired character. Example:

less ubs.html | tr ',' '.' | sed 's/\cM/č/g' > ubs_normal.html

No comments:

Post a Comment