Issue
How to insert a newline before a pattern within a line?
For example, this will insert a newline behind the regex pattern.
sed 's/regex/&\n/g'
How can I do the same but in front of the pattern?
Given this sample input file, the pattern to match on is the phone number.
some text (012)345-6789
Should become
some text
(012)345-6789
Solution
Some of the other answers didn't work for my version of sed.
Switching the position of &
and \n
did work.
sed 's/regexp/\n&/g'
Edit: This doesn't seem to work on OS X, unless you install gnu-sed
.
Answered By - Dennis Answer Checked By - Katrina (WPSolving Volunteer)