sed newline in mac

If you love sed and are using a Mac, you know that its frustrating using newlines \n - using \n in replace part in sed just doesn’t work in Mac :(

For example, below doesn’t replace with newlines

sed 's/search-for/\n/g'

To use newlines in sed in mac, use the following instead

sed 's/search-for/\'$'\n/g'

That is, use \'$'\n instead of simple \n. That gets the job done!!

Published 16 August 2014
comments powered by Disqus