Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing next line with sed

Tags:

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
like image 415
iva123 Avatar asked Sep 29 '10 10:09

iva123


2 Answers

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
like image 180
Gadolin Avatar answered Sep 19 '22 18:09

Gadolin


use awk

awk '/pattern/{getline;print}' file
like image 21
ghostdog74 Avatar answered Sep 17 '22 18:09

ghostdog74