Dennis
Dennis

Reputation: 59449

Shell: adding a new line between a given line of text

What this question isn't asking is how to add a new line below or above every line which matches a pattern.

What I'm trying to do is add a new line between a pattern that exists on one line.

Here is an example.

before:

Monday:8am-10pm

after:

Monday:

8am-10pm

Thus in this case, insert new line after every 'Monday' pattern.

Upvotes: 1

Views: 11149

Answers (4)

vezult
vezult

Reputation: 5243

Using sed:

echo "Monday:8am-10pm" | sed -e 's/:/:\n\n/'

Upvotes: 0

user36457
user36457

Reputation:

sed 's/Monday:/&\n\n/g'

will replace them (supposing you want 2 newlines as shown above)

Upvotes: 2

jthompson
jthompson

Reputation: 7266

sed 's/Monday:/&\n/g'

Upvotes: 5

strager
strager

Reputation: 90012

echo 'Monday:8am-10pm' | sed -e 's/^Monday:/&\n/'

For characters up to ':':

echo 'Monday:8am-10pm' | sed -e 's/^[^:]*:/&\n/'

Upvotes: 6

Related Questions