After readfile can I enumerate the lines using foreach command? I want to read a file line by line, then write some lines out. For example, I have the following lines:

x =1
COMMENT START
this is for test
COMMENT END
y =1

but I only want to write out

x =1
y =1

asked 16 Nov '12, 21:17

gt8967884's gravatar image

gt8967884
116747678
accept rate: 12%


You could use the below code:

 <readFile>
       <name>text</name>
       <path>${file}</path>
 </readFile>
 <while>
    <actionList>
      <setInstallerVariableFromRegEx name="line" pattern="^([^\n]*)(\n|$).*" substitution="\1" text="${text}"/>
      <setInstallerVariableFromRegEx name="text" pattern="^[^\n]*(\n|$)(.*)" substitution="\2" text="${text}"/>
      <!-- Operate over the captured line -->
            <setInstallerVariableFromRegEx name="name" pattern="\s*([^=]+)=([^\n]*)" text="${line}" substitution="\1"/>
            <setInstallerVariableFromRegEx name="value" pattern="\s*([^=]+)=([^\n]*)" text="${line}" substitution="\2"/>
            <setInstallerVariable name="${name}" value="${value}"/>
            <globalVariables names="${name}"/>
     </actionList>
     <conditionRuleList>
        <regExMatch text="${text}" logic="matches" pattern="[^\n]+.*(\n|$)"/>
     </conditionRuleList>
 </while>
link

answered 18 Nov '12, 16:19

juanjo's gravatar image

juanjo ♦♦
5.8k413
accept rate: 23%

edited 31 Aug '15, 07:37

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×2
×2

Asked: 16 Nov '12, 21:17

Seen: 1,239 times

Last updated: 31 Aug '15, 07:37