简体   繁体   中英

non ascii special char remove from csv file

While i am editing csv file in linux special character look like £stackoverflow, £unixbox,£query. My query is how to remove  from csv file.

Input: £stackoverflow, £unixbox,£query Output: £stackoverflow, £unixbox,£query

Observations of linux box: currently linux window translation setting is ISO-8859-1, while i am changing the window setting--->translation-->UTF-8 then open the same file using vi editior  char being disappeared.I have tried iconv command as well but didn't work.It may be the reason that i am conv the file ISO-8859-1 to UTF-8 but by default setting of linux is ISO-8859-1 so it is showing me  it is not removing this char.How to handle it to remove the same.

You can try the below Perl solution. This removes all the ordinal values that are not in the range of 32 to 127 (which contains the ascii text)

$ echo "£stackoverflow, £unixbox,£query Output: £stackoverflow, £unixbox,£query" | perl -pe ' s/[^\x20-\x7f]//g '
stackoverflow, unixbox,query Output: stackoverflow, unixbox,query
$

EDIT:

To remove just Â, use

$ echo "Â" | perl -pe ' s/./sprintf("%x |",ord($&))/eg '  # Find the underlying ordinal values for  
c3 |82 |

$ echo "£stackoverflow, £unixbox,£query" | perl -pe ' s/\xc3\x82//g ' #removing it using s///
£stackoverflow, £unixbox,£query

$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM