Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new line using sed on MacOS?

Tags:

I wanted to add a new line between </a> and <a><a>

</a><a><a>  </a> <a><a> 

I did this

sed 's#</a><a><a>#</a>\n<a><a>#g' filename but it didn't work.

like image 219
codereviewanskquestions Avatar asked May 15 '13 22:05

codereviewanskquestions


People also ask

How do I add a new line in sed?

The sed command can add a new line after a pattern match is found. The "a" command to sed tells it to add a new line after a match is found. The sed command can add a new line before a pattern match is found. The "i" command to sed tells it to add a new line before a match is found.

Does sed command work on Mac?

One way to make the GNU version of the SED to work on the Mac OS X, is to directly install the gnu-sed along with the default names which will assure you that you won't have to run different commands on both the operating systems.

What is sed command in Mac?

SED is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits, SED works by making only one pass over the input(s), and is consequently more efficient.


1 Answers

Powered by mac in two Interpretation:

  1. echo foo | sed 's/f/f\'$'\n/'
  2. echo foo | gsed 's/f/f\n/g'
like image 105
Max Avatar answered Nov 12 '22 06:11

Max