ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sed -i 's/\//g' file.csv
works ok if run from commandline, but running from script, it's not working. Why?
i see no reason why it shouldn't work, other than that your bash script file isn't utf-8 encoded?
are you using the exact same command?
so you alwys make a copy of the original file.csv before attempting it?
what does the euro sign look like inside the .csv file?
Hmmm... doing cat or vi on the csv file, the symbol looks like €.
Opening the csv file in excel, the euro-symbol is displayed as โ‚ฌ
I should add that this is a csv file converted from excel using: libreoffice --headless --convert-to csv file.xlsx --infilter=CSV:59,34,UTF8
Mayber the infilter is wrong?
I chosed 59 because I think that means semicolon as separator, but I don't really know what I'm doing.
It works as expected on other excel files though, but ran into problems now when the excel sheet contains €...
‘tr -d €’ is not a correct solution. Observe how it corrupts characters other then euro sign:
Code:
$ echo '<ż๓łw €>' | tr -d €
<ż๓ลw >
This is because tr does not understand Unicode and operates on bytes and € are two bytes.
To delete all non-ASCII characters, you need ‘tr -d '\200-\377' as in:
Code:
$ echo '<ż๓łw €>' | tr -d '\200-\377'
<w >
To delete just the euro sign use sed as has been mentioned by others. If your script doesn’t work, ‘hexdump -C’ can help you find out differences in encoding that may cause that. You can also explicitly encode the character:
Code:
$ echo '<ż๓łw €>' | sed $'s/\342\202\254/EURO/'
<ż๓łw EURO>
though (notice this uses $'…' which is bash extension and) I don’t think you should be needing to do that since just using € should work if you save your files in the same encoding.
Lastly, you can play around with iconv to do various things to your input file, e.g.:
Try the following. I don't know if single or double quotes are needed or if it matters at all which you use. I changed the delimiter to # for readability.
Code:
sed -i 's#\xe2\x82\xac##g' file.csv
sed -i "s#\xe2\x82\xac##g" file.csv
Last edited by tofino_surfer; 12-11-2018 at 02:57 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.