Replace special characters

Eric Cone
2014-02-20
2014-02-21
  • Eric Cone
    Eric Cone
    2014-02-20

    I need to set a variable such as:
    {http://test.com#key word|http://url.com#my name}

    then I need to replace:
    http://www.yoururl.com

    with the variable (which may be 1000 characters in lenth or more sometimes)

    Can this be done with sfk? I was trying to accomplish it in a batch file with sed and I ccould not set a dos variable with all these special characters and sed chokes on all the special characters because I am not escaping them correctly.

    Any help is appreciatd. I really need to learn C# or VB.NET because this is rough.

     
  • stahlworks
    stahlworks
    2014-02-21

    If you want to replace by a simple string like "http://test.com#key word"
    then use in a Windows .bat file

    set mypattern=http://test.com#key word
    sfk replace test.txt "_http://www.yoururl.com_%mypattern%_" -yes
    

    Which replaces the yoururl.com in a single file test.txt. If, however, you want to replace by a string "{http://test.com#key word|http://url.com#my name}" then the "|" redirect character makes problems. Rewrite this character by it's ASCII code like \x7c and use:

    set mypattern={http://test.com#key word\x7chttp://url.com#my name}
    sfk replace test.txt -spat "_http://www.yoururl.com_%mypattern%_" -yes
    

    The -spat option does the interpretation of \x7c, changing it back to "|" during replace.