[Linux-disciples] Deleting all non-ASCII characters
Stephen R Laniel
steve at laniels.org
Thu Jul 17 10:43:36 EDT 2008
On Thu, Jul 17, 2008 at 10:37:40AM -0400, Stephen R Laniel wrote:
> #!/usr/bin/perl
> use strict;
> use warnings;
> while(<>) {
> s#[^[:ascii:]]##g;
> print;
> }
I believe that can actually be reduced
to this one-liner:
perl -n -e 's#[^[:ascii:]]##g' /path/to/file
That will dump its output to stdout. If
you want to modify the file in place,
just add a '-i' option before the '-n'.
'-i' here does the same thing as
'sed -i' does.
(In general, if you've not spotted this
already, UNIX command-line tools share a
lot of command-line arguments. E.g., -v
tends to mean either 'give verbose
output' or "print the program's version
number and exit"; -q means "spit out
minimal output": it's the opposite of
the verbose -v option.)
--
Stephen R. Laniel
steve at laniels.org
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
More information about the Linux-disciples
mailing list