user601836 user601836 - 5 months ago 13
Bash Question

how to insert new line after a specific character in scripts

I have the following (example.txt) file:

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


how can I achieve in unix the following result?

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

Answer

The following in-line sed script will replace a space with a newline, and should solve your problem.

sed -i 's/ /\n/g' example.txt > example_out.txt
Comments