shelljenkinsfindreplaceallhar

How to replace a values present of a url in a text file


I have a har file which consist of lot of http values and site information. my requirement is to find and replace the "http://testing.smart" to "http://staging.smart" in all occurrences of the same file. How to do this in shell ?

Example
test.har

Output:
Replace all "http://testing.smart" modified to "http://staging.smart" in test.har

Thanks!!

Solution

  • You can use the sed command

    sed -i 's/<regex (or word) to change>/<new word>/g' <file path>
    

    Most tutorials or manuals use the slash as delimiter but you can use another character to avoid conflicts. So:

    sed -i 's#<regex (or word) to change>#<new word>#g' <file path>
    

    In your case you would do it like this

    sed -i 's#http://testing.smart#http://staging.smart#g' test.har