Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

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
2  
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
show 1 more comment

Your Answer

 
discard

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.