3

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:
http://pastebin.com/raw.php?i=zjMGHNq5

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!

1 Answer 1

4

'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
6
  • 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 Mar 22, 2011 at 12:52
  • @johnny8888 It looks like Busybox has a bug in their tr implementation. I added a workaround. Mar 22, 2011 at 16:14
  • i tried: pastebin.com/raw.php?i=Jnbxn0MX Mar 22, 2011 at 17:07
  • 2
    I see the same bug on my router. But tr -cd '\011\012 -~' works. Mar 22, 2011 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! Mar 23, 2011 at 22:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .