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

后端 未结 12 2337
春和景丽
春和景丽 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 06:15

    All the above solutions have deficiencies where the last search string is repeated elsewhere in the string. I found it best to write a bash function.

        function str_str {
          local str
          str="${1#*${2}}"
          str="${str%%$3*}"
          echo -n "$str"
        }
    
        # test it ...
        mystr="this is a string"
        str_str "$mystr" "this " " string"
    

提交回复
热议问题