1

I tried to write a bash-script to replace things like:

{"Ausstattung":"

"},{"Ausstattung":"

"}

in all CSV files of a subfolder.

This is what I am using so far:

function suche_und_ersetze() { // search and replace
   LC_ALL=C find ./subfolder -type f ! -name ".DS_Store" -exec sed -i "" "s/${OLD}/${NEW}/g" {} \; 
}

OLD='{\"Ausstattung\":\"' 
NEW="#" 
suche_und_ersetze

OLD='\"},{\"Ausstattung\":\"'
NEW=" #" 
suche_und_ersetze

OLD='\"}' 
NEW="" 
suche_und_ersetze

Somehow I can't make it work. The script is replacing text without " or } or ,, but not the upper listed words.

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • You'll want to pass your OLD and NEW variables as parameters to your function. They can then be called with `$1` and `$2`. Bash goes from top to bottom, your `suche_und_ersetze` function doesn't know what `${OLD}` and `${NEW}` are – SimonC Jan 13 '20 at 13:49
  • Thank you @SimonC-ReinstateMonica. It is working with other Texts, f.ex. only Ausstattung. But not with the Brackets... – Christian Fröhlich Jan 13 '20 at 14:03
  • I did some language polishing and a bit of translation to English to improve readability. – B--rian Jan 13 '20 at 15:07
  • Does this answer your question? [Which characters need to be escaped when using Bash?](https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash) – B--rian Jan 13 '20 at 15:09

1 Answers1

0

Sorry, i should have looked into the csv with an editor:

It is ""},{""Ausstattung"":"" and not "},{"Ausstattung":"

In sed you even don't need to escape " if you use '

  • Please try rewording your answer, https://www.deepl.com/ might help you. In the current form it is hard to guess what you suggest. – B--rian Jan 13 '20 at 15:10