-1

I have a big file with al lot of commas now I want to replace all those commas for a space.

So for example: I went to the park,with,him, after that,we,go,to the car What I want: I went to the park with him after that we go to the car

( also its a big file so just literally every comma needs to get out does not matter which position )

Any idea?

1 Answers1

1

This command will replace a comma with a space in the file test.txt

sed -i 's/,/ /g' test.txt

This article explains how sed works https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/

Toasty140
  • 131
  • 6
  • Hey that worked, can you maybe explain me what the s/ and /g stands for? – Mister-Robot May 25 '21 at 22:03
  • 1
    so s/ is the function for "Find and replace." /g is global. if you got rid of "g", it would only replace the first occurrence. I strongly recommend reading the article and checking out the man pages to understand more about what sed does. – Toasty140 May 25 '21 at 22:17
  • `y/,/ /` might be more idiomatic for simple transliterations - see for example [Can I use `sed` to translate characters like with `tr`?](https://unix.stackexchange.com/questions/392035/can-i-use-sed-to-translate-characters-like-with-tr/392036#392036) – steeldriver May 25 '21 at 22:26