iva123
iva123

Reputation: 3515

Printing next line with sed

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

Upvotes: 6

Views: 21090

Answers (2)

Gadolin
Gadolin

Reputation: 2686

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

Upvotes: 19

ghostdog74
ghostdog74

Reputation: 343201

use awk

awk '/pattern/{getline;print}' file

Upvotes: 3

Related Questions