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

后端 未结 12 2537
春和景丽
春和景丽 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:49

    You can use two s commands

    $ echo "Here is a String" | sed 's/.*Here//; s/String.*//'
     is a 
    

    Also works

    $ echo "Here is a StringHere is a String" | sed 's/.*Here//; s/String.*//'
     is a
    
    $ echo "Here is a StringHere is a StringHere is a StringHere is a String" | sed 's/.*Here//; s/String.*//'
     is a 
    

提交回复
热议问题