0

我正在尝试在 ant 中进行一些小的文件操作。我检索了一个表空间列表,我想在 ALTER TABLESPACE 前面加上 NOT LOGGED ,如下所示:

    <loadfile property="zos.prepend.tablespaces" srcFile="${basedir}/zos-tablespaces-DIRTY.txt">
      <filterchain>
        <!-- Order here is important -->
        <prefixlines prefix="ALTER TABLESPACE "/>
        <suffixlines suffix=" NOT LOGGED"/>
        <trim/>
        <replaceregex pattern=".*NAME.*|.*-----.*|.*record.*select.*|^ALTER TABLESPACE$" replace=""/>
        <trim/>
        <ignoreblank/>
      </filterchain>
    </loadfile>

    <echo file="${basedir}/zos-tablespaces-PREPEND.txt">
        ${zos.prepend.tablespaces}
    </echo>

当我这样做时,我得到了前置,但附加似乎附加到下一行。任何想法如何做前缀和后缀?

4

1 回答 1

1

我其实只是想通了。我在输入的每一行末尾的 CRLF 之后添加后缀行,而不是在之前添加。所以我只需要在添加后缀后清除 CRLF。这就是最终奏效的方法。现在我只需要让它更干净一点

<filterchain>

  <tabstospaces/>
  <prefixlines prefix="ALTER TABLESPACE "/>
  <trim/>
  <replaceregex pattern=".*NAME.*|.*record.*select.*|.*-----.*|^ALTER TABLESPACE$" replace=""/>
  <suffixlines suffix=" NOT LOGGED @"/>
  <striplinebreaks/>
  <tokenfilter>
  <replacestring from="LOGGED @" to="LOGGED @${line.separator}"/>
  </tokenfilter>
  <tabstospaces/>
  <trim/>
  <replaceregex pattern="^NOT LOGGED @$" replace=""/>
  <tabstospaces/>
  <trim/>       
  <ignoreblank/>
  <fixcrlf eol="crlf" eof="add"/>

</filterchain>
于 2013-04-16T19:20:52.060 回答