Read file without replacing ${xxx} as variable

Comments

5 comments

  • Avatar
    BitRock support

    Hi Michaela,

    We are sorry for the late reply. We have been facing some spam issues and we missed your post.

    A possible way of doing this is extracting just the exact text you want to replace using <setInstallerVariableFromRegEx?, then apply a <substitute> action in "exact" mode. Please find below an example:

     <readFile>
    <name>file_content</name>
    <path>${file}</path>
    </readFile>
    <setInstallerVariableFromRegEx>
    <name>text_to_substitute</name>
    <pattern>^.*?(${pattern}).*$</pattern>
    <substitution>\1</substitution>
    <text>${file_content}</text>
    </setInstallerVariableFromRegEx>
    <substitute>
    <files>${file}</files>
    <type>exact</type>
    <substitutionList>
    <substitution>
    <pattern>${text_to_substitute}</pattern>
    <value>${substitution}</value>
    </substitution>
    </substitutionList>
    </substitute>

    Please note this won't work if the selected text includes a variable with ${xxx} syntax.

    Would the above work for you?

    Looking forward to your feedback,
    Alejandro

  • Avatar
    mlukasova

    Hello,
    I need to do multiline substitution. It does not seem that the last step with substitution works.
    I tried to use this solution https://support.bitrock.com/hc/en-us/community/posts/115002745069-Can-I-perform-a-Multi-line-regex-text-file-substitution-

    but the variables in cmake with ${xxx} convention were replaced with ***unknown variable xxx***

     

    Thank you, Michaela

  • Avatar
    BitRock support

    Hi Mlukasova,

    Could you check if the workaround described in the following post would work for you?

    https://support.bitrock.com/hc/en-us/community/posts/115002029705-How-do-I-read-and-display-a-shell-script-that-contains-shell-variables-like-0-

    Best regards,

    Michiel

     

  • Avatar
    mlukasova

    Hi,
    no it will not help. I will try to explain it one more time.

    I have cmake file, which contains about 5 lines that i have to replace with one line. It also contains lot of variables like ${SIM_DIR} etc. I think i now have only one solution - i read the file with custom readFileEscapeVars , then I have to setInstalerVariableFromRegex but it will replace these ${variables} and if not, the writeFile will. So i think i need some custom function to set variable from regex without replacing ${variables} and also writeFile without replacing ${variables}. Do you think it is the only way? And if it is, is it possible that you create some functions like this?

    Thank you,
    Michaela

  • Avatar
    BitRock support

    Hi Michaela,

    Please accept my apologies for the delay in my reply, we are currently investigating a solution for this. I will contact you as soon as possible with further information.

    Best regards,

    Michiel

Please sign in to leave a comment.