How to insert strings containing slashes with sed?

前端 未结 11 958
别那么骄傲
别那么骄傲 2020-11-22 04:44

I have a Visual Studio project, which is developed locally. Code files have to be deployed to a remote server. The only problem are the URLs they contain, which are hard-cod

11条回答
  •  野的像风
    2020-11-22 05:14

    this line should work for your 3 examples:

    sed -r 's#\?(page)=([^&]*)&#/\1/\2#g' a.txt
    
    • I used -r to save some escaping .
    • the line should be generic for your one, two three case. you don't have to do the sub 3 times

    test with your example (a.txt):

    kent$  echo "?page=one&
    ?page=two&
    ?page=three&"|sed -r 's#\?(page)=([^&]*)&#/\1/\2#g'
    /page/one
    /page/two
    /page/three
    

提交回复
热议问题