How to insert a new line after a certain character in scripts

I have the following file (example.txt):

blue(4) red(8) green(5) yellow(19) brown(60) black(5)

how can i achieve the following result in unix?

blue(4) 
red(8) 
green(5) 
yellow(19) 
brown(60) 
black(5)
+5
source share
4 answers

The following built-in sed script will replace the space with a new line and should solve your problem.

sed -i 's/ /\n/g' example.txt > example_out.txt
+4
source

If you need to insert a new line after closing the brackets, try

sed 's/) \?/)\n/g' example.txt
+5
source
xargs -n 1 < example.txt 

example.txt xargs -n 1, xargs .

, , -n 1 -n 2

-n max-args .

+4

sed, :

sed 's/ /\n/g' example.txt
+2

All Articles