Printing next line with sed

后端 未结 2 980
萌比男神i
萌比男神i 2021-01-14 19:13

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

I tried this command but it gives error :

sed -n \'// { N p}/\' test.x         


        
相关标签:
2条回答
  • 2021-01-14 19:47

    use awk

    awk '/pattern/{getline;print}' file
    
    0 讨论(0)
  • 2021-01-14 20:04

    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
    
    0 讨论(0)
提交回复
热议问题