Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

perl is not a very good idea, because it's an OpenWrt router, so not enough space for it.
"cat -v" doesn't works, because it doesn't supports the "-v" option

Any ideas? :\

Here's a bad text:

Between the "review" and the "kde" word, theres a non-printable char. For example i need to remove these kind of chars for texts :\
Thank you!

share|improve this question
up vote 3 down vote accepted

'tr' can be used for this. Normally, you could do the following:

tr -cd '\11\12\15\40-\176' < raw.php

This deletes any characters that aren't one of the ones listed. The \NNN notation represents the character in octal, this lets us get tab, newline, carriage return in addition to the other characters.

Busybox's tr currently has a bug when it comes to using octal character representation and ranges. Instead, this might cover you:

tr -cd '[:alnum:][:punct:][:space:]' < raw.php
share|improve this answer
thanks! it works under bash/fedora, ok. but with openwrt...the shell is: "ash"/busybox.. it just gives an empty line, if i: pastebin.com/raw.php?i=J1kSv89F – LanceBaynes Mar 22 '11 at 12:52
@johnny8888 It looks like Busybox has a bug in their tr implementation. I added a workaround. – Shawn J. Goff Mar 22 '11 at 16:14
i tried: pastebin.com/raw.php?i=Jnbxn0MX – LanceBaynes Mar 22 '11 at 17:07
I see the same bug on my router. But tr -cd '\011\012 -~' works. – Gilles Mar 22 '11 at 20:47
WOW! tr -cd '\011\012 -~' really does work!! but how? what does it exactly do? it only allows exactly what chars? can you post you're answer in an "answer" so i could put a tick to it?? THANK YOU! – LanceBaynes Mar 23 '11 at 22:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.