How to delete non-ASCII chars in file

Giorgos Keramidas keramida at
Fri Sep 5 17:39:00 UTC 2008

On Fri, 5 Sep 2008 12:27:12 -0400, "Mark B." <mkbucc at> wrote:
> On Fri, Sep 5, 2008 at 10:58 AM, Giorgos Keramidas
> <keramida at> wrote:
>> $ echo '^Fhello^F' | sed -e 's/[^[:print:]]*//' | hd
>> 00000000  68 65 6c 6c 6f 06 0a                              |hello..|
>> 00000007
>> $
> In case you are interested, I've patched the re_format man page with
> this example.  I had read it, and it says :print: is the "name of the
> character class."  I think the concrete example helps clarify things.

Excellent, thank you!  Using your text as a starting point, I've
committed two examples to the manpage now: one for matching the
characters of a class, and one for matching all the characters *not* in
a class.

Index: re_format.7
--- re_format.7	(revision 182794)
+++ re_format.7	(working copy)
@@ -288,6 +288,14 @@
 A locale may provide others.
 A character class may not be used as an endpoint of a range.
+A bracketed expression like
+.Ql [[:class:]]
+can be used to match a single character that belongs to a character
+The reverse, matching any character that does not belong to a specific
+class, the negation operator of bracket expressions may be used:
+.Ql [^[:class:]] .
 There are two special cases\(dd of bracket expressions:
 the bracket expressions
 .Ql [[:<:]]

Does this look ok?  If not, we can commit a followup change and refine
it in the next 2-3 days.  Then I'll file an MFC request with our release
engineering team, and merge it to stable branches too.

> A follow question--is it possible to use that statement in a Makefile
> (BSD)?  A straight cut 'n paste didn't work, and I couldn't figure out
> the escaping to make it work.

It should be possible.  Quoting may be a bit trickier in Makefiles, but
can you show me the Makefile you tried?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
Url :

More information about the freebsd-questions mailing list