Replace special characters

Eric Cone
  • Eric Cone

    Eric Cone - 2014-02-20

    I need to set a variable such as:
    { word| 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

    stahlworks - 2014-02-21

    If you want to replace by a simple string like " word"
    then use in a Windows .bat file

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

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

    set mypattern={ word\x7c 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.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks