Issue
I trying to use sed in finding a matching pattern in a file then deleting the next line only.
Ex.
Location
New York <---- delete
USA
I tried sed '/Location/{n; d}'
that work on linux but didn't work on solaris.
Thanks.
Solution
As I mentioned in my answer about your other sed question, Solaris sed
is old-school AND needs more hand-holding (or to put it another way), is more fussy about it's syntax.
All you need is an additional ';' char placed after the `d' char, i.e.
sed '/Location/{n; d;}'
More generally, anything that can be on a new-line inside {...}
needs a semi-colon separator when it is rolled up onto a single line. However, you can't roll up the 'a', 'i', 'c' commands onto a single line as you can in Linux.
In Solaris standard sed, the 'a', i', 'c' commands need a trailing '' with NO spaces or tabs after it, as much data as you like (probably within some K limit) on \n
terminated lines (NO \r
s), followed by a blank line.
Newer installations of Solaris may also have /usr/xpg4/bin/sed
installed. Try
/usr/xpg4/bin/sed '/Location/{n; d}'
If you're lucky, it will support your shortcut syntax. I don't have access to any solaris machines anymore to test this.
Finally, if that doesn't work, there are packages of GNU tools that can be installed that would have a sed
that is much more like what you're used to from Linux. Ask your sys-admins if GNU tools are already there, or if they can be installed. I'm not sure what version of gnu sed
started to support 'relaxed' syntax, so don't assume that it will be fixed without testing.
Answered By - shellter Answer Checked By - Cary Denson (WPSolving Admin)