Remove non-ASCII characters from CSV

Sujit picture Sujit · Jul 26, 2010 · Viewed 102.8k times · Source

I want to remove all the non-ASCII characters from a file in place.

I found one solution with tr, but I guess I need to write back that file after modification.

I need to do it in place with relatively good performance.

Any suggestions?

Answer

ssegvic picture ssegvic · Jul 26, 2010

A perl oneliner would do: perl -i.bak -pe 's/[^[:ascii:]]//g' <your file>

-i says that the file is going to be edited inplace, and the backup is going to be saved with extension .bak.