Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed on mac: 'extra characters after p command'

Tags:

regex

macos

sed

On Linux I use this to get the next two lines after the [test] line:

sed -n '/\[test\]/{n;p;n;p}' my-file

On Mac I get:

sed: 1: "/\\[test\\]/{n;p;n;p}": extra characters at the end of p command.

Is there an expression that works on both platforms or on Mac a completely different command must be used?

like image 887
julius Avatar asked Sep 05 '16 07:09

julius


1 Answers

Additionally, if you happen to get this error when using the -i option without an extension:

> sed -i 's/foo/bar/g' file
sed: 1: "file": extra characters at the end of p command

In this case the solution is to explicitly set the extension to an empty string:

> sed -i '' 's/foo/bar/g' file
like image 128
Sylver Avatar answered Sep 30 '22 02:09

Sylver