0

I have a large file that looks like this

(something,something1,something2),(something,something1,something2)

how do I use sed and find ),( and replace it with );( or add a newline between the parentheses that has a comma character.

I did try sed 's/),(/),\n(/g' filename.txt but for some reason it does not work

Cyrus Zei
  • 2,589
  • 1
  • 27
  • 37
  • 2
    How did it fail when you tried it? – Benjamin W. Sep 25 '18 at 18:26
  • 2
    Welcome to SO. Stack Overflow is a question and answer site for professional and enthusiast programmers. The goal is that you add some code of your own to your question to **show at least the research effort** you made to solve this yourself. – Cyrus Sep 25 '18 at 18:27
  • 1
    If you have read any manual or tutorial on sed, this should be pretty much the first thing you learn how to do. So that is a good indication that you did not take the first step in solving this yourself. – Mad Physicist Sep 25 '18 at 18:28
  • [How to replace a pattern with newline (\n) with sed under UNIX / Linux operating systems?](https://stackoverflow.com/q/23940591/3776858) or [How do I replace a string with a newline using a bash script and sed?](https://stackoverflow.com/q/23522132/3776858) or [How do I replace : characters with newline?](https://stackoverflow.com/q/16565487/3776858) ... – Cyrus Sep 25 '18 at 18:30
  • 1
    Possible duplicate of [How do I replace a string with a newline using a bash script and sed?](https://stackoverflow.com/questions/23522132/how-do-i-replace-a-string-with-a-newline-using-a-bash-script-and-sed) – Benjamin W. Sep 25 '18 at 18:35
  • yeah, I did look that up and I am not that good at regEx. The command I have tried is sed 's/),(/),\n//g' – Cyrus Zei Sep 25 '18 at 18:53

2 Answers2

0

for those who come here and want to know how this work without getting a lot of stackoverflow "greetings"

since I was on Mac os x you need to replace your \n with \'$'\n'' so to find ),( and add a new line between the parentheses this is the command I used sed 's/;/\'$'\n''/g' testdone.txt > testdone2.txt

ES

Cyrus Zei
  • 2,589
  • 1
  • 27
  • 37
0
echo "(something,something1,something2),(something,something1,something2)" | sed "s|),(|);(|"

This prints the below for me.

(something,something1,something2);(something,something1,something2)

For new line

echo "(something,something1,something2),(something,something1,something2)" | sed "s|),(|)\n(|"

And the above prints the below.

(something,something1,something2)
(something,something1,something2)
Sparrow
  • 146
  • 10