Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


Replace special characters

Eric Cone
  • Eric Cone
    Eric Cone

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

    then I need to replace:

    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

    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.