Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Removing Non-Ascii chars from text file

by citromatik (Curate)
on Jun 07, 2007 at 12:42 UTC ( #619799=note: print w/replies, xml ) Need Help??


in reply to Removing Non-Ascii chars from text file

You can do the job with a perl one-liner:

perl -i.bk -pe 's/[^[:ascii:]]//g;' file

This will remove all non ascii character from your file copying the original content in file.bk

citromatik

Replies are listed 'Best First'.
Re^2: Removing Non-Ascii chars from text file
by freonpsandoz (Acolyte) on Oct 02, 2016 at 05:06 UTC

    You also need to be aware of what the encoding of the file is and what encoding Perl defaults to on your system. For a UTF-8 file on Windows, I found that I needed to add "use open qw(:std :utf8);" before the "s///" command so that Perl would expect the input to be UTF-8.

Re^2: Removing Non-Ascii chars from text file
by Anonymous Monk on Aug 04, 2015 at 08:22 UTC
    You've made my day :) busy with csv parsing and couldn't get rid of " € 1.000 " from one of the fields
      Sounds more like wrong encoding, though.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^2: Removing Non-Ascii chars from text file
by Anonymous Monk on Jul 08, 2016 at 12:15 UTC
    This works. I just don't want the backup file. How to do that.

      See perlrun on what the switches do. For your case especially relevant is the -i switch, which takes an optional parameter.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://619799]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2019-07-16 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?