-1

I am trying to replace the fancy quotation characters „ “ with normal " character. To do that I did the following but it did not change them. what should I do instead ?

sed -i 's/„/"/g' myfile.csv

Here is the SS of a single sentence from myfile.csv

enter image description here

EDIT: Textual version of the SS placed above:

Glaubt man Union und FDP, dann wird ihre "Energiewende" mehr als nur ein Ausstieg – sie soll ein "Umstieg" werden.

Note: when I copy paste, the special character disappears. That is why I put screenshot at first.

zwlayer
  • 1,752
  • 1
  • 18
  • 41
  • And don't post screenshots of text files. – Michael Vehrs Aug 14 '18 at 15:28
  • How are you examining the file? Can you please extract the relevant part, and if you're unable to copy-paste it as-is, can you base64 encode it? Double-check that it's correct by copying it back from your post and ensure that both show the same. – that other guy Aug 14 '18 at 15:35
  • You could try dumping the file with `od -c` or something similar, and then using the codes in your `sed` program. – Michael Vehrs Aug 14 '18 at 15:40
  • I am unable to reproduce the problem, just tested this in bash and worked fine for replacing character `„`. – Paolo Aug 14 '18 at 21:47
  • Possible duplicate of [How do I replace single quotes with another character in sed?](https://stackoverflow.com/q/17357952/608639), [Escape a string for a sed replace pattern](https://stackoverflow.com/q/407523/608639), [What characters do I need to escape when using sed in a sh script?](https://stackoverflow.com/q/407523/608639), [sed command replace text with ' character](https://askubuntu.com/q/315344), etc. – jww Aug 15 '18 at 01:43

2 Answers2

0

You could use tr for example:

$ tr '„“' '"' < myfile.csv

You could try it like this:

$ echo "dann wird ihre „Energiewende“ mehr" | tr '„“' '"'
dann wird ihre "Energiewende" mehr
nbari
  • 25,603
  • 10
  • 76
  • 131
-1

You need to make two replacements, one for the opening quotes and one for the closing quotes. In other words:

sed -i 's/„/"/g;s/“/"/g' myfile.csv

or

sed -i 's/[„“]/"/g' myfile.csv

since you are replacing both with the same character.

Michael Vehrs
  • 3,293
  • 11
  • 10
  • Sure but I think my command should have replaced either of them. However it did not change. – zwlayer Aug 14 '18 at 15:24
  • 2
    @zwlayer You shouldn't berate somebody who tries to help you. Rather, you should create an example with your actual input - how are we supposed to know what exact character your input contains if you can't post an example containing it? Michael's commands are absolutely correct and will replace `„` and `“` with `"`. Maybe you have different smart quotes? – Benjamin W. Aug 14 '18 at 15:33