regular expression - count lines in stdout?

Comments

2 comments

  • Avatar
    juanjo

    You could use the below code:

    <setInstallerVariable name="number" value="1"/>
    <while>
        <actionList>
            <mathExpression>
               <text>${number} + 1</text>
               <variable>number</variable>
            </mathExpression>
            <setInstallerVariableFromRegEx>
                <name>program_stdout</name>
                <pattern>^[^\n]*\n(.*)</pattern>
                <substitution>\1</substitution>
                <text>${program_stdout}</text>
            </setInstallerVariableFromRegEx>
        </actionList>
        <conditionRuleList>
            <regExMatch>
                <logic>matches</logic>
                <pattern>^[^\n]*\n(.*)</pattern>
                <text>${program_stdout}</text>
            </regExMatch>
        </conditionRuleList>
    </while>
    

    Please note that any double backslashes should be converted to single backslashes.

  • Avatar
    juanjo

    If you just need that on Unix, you could call wc:

    <setInstallerVariableFromScriptOutput>
        <exec>echo</exec>
        <execArgs>"${program_stdout}" | wc -l</execArgs>
        <name>count</name>
    </setInstallerVariableFromScriptOutput>
    

Please sign in to leave a comment.