Sed print between patterns the first match result

前端 未结 2 873
忘掉有多难
忘掉有多难 2021-01-29 06:04

the file like:

File /home/user/

int yl_init(void);

File /home/user/

int yl2_init(void);

I want u

相关标签:
2条回答
  • 2021-01-29 07:05

    This might work for you (GNU sed);

    sed '/File/,/;/!d;/;/q' file
    
    • /File/,/;/!d delete all lines not between File and ;
    • /;/q quit on encountering a line containing ;
    0 讨论(0)
  • 2021-01-29 07:05

    You can use a the q command to cause sed to exit when the second pattern is matched:

    sed -n '/File/,$p;/;/q'
    
    0 讨论(0)
提交回复
热议问题