Hello,
command | sed -n /regex/{N;p}
should print the line right after the matched one. Instead it prints both lines, the matched one and the one behind that.
Nope. You need to go read the manual again.
(if you ignore the POSIX violation of failing to place a newline before the closing brace), should do exactly what you say it is doing, i.e. print both the matched line, and the following line.
http://www.gnu.org/software/sed/manual/sed.html#Other-Commands |N | Add a newline to the pattern space, then append the next line | of input to the pattern space. If there is no more input then sed | exits without processing any more commands.
http://www.gnu.org/software/sed/manual/sed.html#Common-Commands |p | Print out the pattern space (to the standard output). This command | is usually only used in conjunction with the -n command-line option.
Hello,
command | sed -n /regex/{N;p}
should print the line right after the matched one.
Instead it prints both lines, the matched one and the one behind that.
Nope. You need to go read the manual again.
command | sed -n /regex/{N;p}
(if you ignore the POSIX violation of failing to place a newline before the closing brace), should do exactly what you say it is doing, i.e. print both the matched line, and the following line.
http://www.gnu.org/software/sed/manual/sed.html#Other-Commands
|N
| Add a newline to the pattern space, then append the next line
| of input to the pattern space. If there is no more input then sed
| exits without processing any more commands.
http://www.gnu.org/software/sed/manual/sed.html#Common-Commands
|p
| Print out the pattern space (to the standard output). This command
| is usually only used in conjunction with the -n command-line option.