How to use sed/grep to extract text between two words?

后端 未结 12 2360
春和景丽
春和景丽 2020-11-22 05:25

I am trying to output a string that contains everything between two words of a string:

input:

\"Here is a String\"

output:

12条回答
  •  失恋的感觉
    2020-11-22 05:48

    This might work for you (GNU sed):

    sed '/Here/!d;s//&\n/;s/.*\n//;:a;/String/bb;$!{n;ba};:b;s//\n&/;P;D' file 
    

    This presents each representation of text between two markers (in this instance Here and String) on a newline and preserves newlines within the text.

提交回复
热议问题