6

I want to print next line of matching word with sed.

I tried this command but it gives error :

sed -n '/<!\[CDATA\[\]\]>/ { N p}/' test.xml
iva123
  • 3,395
  • 10
  • 47
  • 68

2 Answers2

18

what about grep -e -A 1 regex? It will print line below regex.

With sed, looking for pattern "dd", below works fine as you would:

sed -n '/dd/ {n;p}' file

For file content:

dd
aa
ss
aa

It prints:

aa
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Gadolin
  • 2,636
  • 3
  • 28
  • 33
2

use awk

awk '/pattern/{getline;print}' file
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
  • `/bin/gawk` is about 6 times larger than `/bin/sed` on Linux. On other OSes the ratio is similar, even if the `awk` is not from GNU... – Mikhail T. Jun 27 '18 at 14:29