【问题标题】:How can I adapt a unix Perl command to Windows?如何使 unix Perl 命令适应 Windows?
【发布时间】:2019-10-15 20:43:51
【问题描述】:

https://oracle-base.com/articles/misc/install-sample-schemas。 Tim Hall 建议使用以下命令(一旦定位在特定目录中)将字符串 __SUB__CWD__ 替换为 sql 文件和 dat 文件中的当前目录名称:

cd ...
perl -p -i.bak -e 's#__SUB__CWD__#'$(pwd)'#g' *.sql */*.sql */*.dat

如何使这个命令适应 Windows? 即使目录的名称是不变的(例如:C:\app\soutou\product\18.0.0\dbhomeXE\demo\schema)。我不是 Perl 的用户(Oracle 开发者)

【问题讨论】:

    标签: windows perl


    【解决方案1】:

    如果您在 Windows 机器上安装 Strawberry Perl,则此命令应该只能在 cmd.com shell 中运行

    perl -i.bak -MCwd -pe"BEGIN{ $cwd = cwd; @ARGV = map glob, @ARGV; } s#__SUB__CWD__#$cwd#g" *.sql *\*.sql *\*.dat
    

    【讨论】:

    • 谢谢,但是使用 Active Perl 这个命令返回Can't find string terminator "'" anywhere before EOF at -e line 1.
    • 这可能是一个长镜头,但我记得cmd.exe 有单引号问题。尝试用双引号替换它们:perl -MCwd -p -i.bak -e "BEGIN{ $cwd = cwd } s#__SUB__CWD__#$cwd#g" *.sql *\*.sql *\*.dat
    • 感谢它现在产生Can't open *.sql: Invalid argument. Can't open *\*.sql: Invalid argument. Can't open *\*.dat: Invalid argument.
    • @ChristianSoutou 另见this question
    • @Hakon Haegland,谢谢你是对的,它适用于单个文件名(作为 test.sql 而不是 *.sql)。我要试试 Cygwin
    【解决方案2】:

    对于 Windows 上的 Oracle RDBMS,您可以使用 perl 方法的替代方法:

    Get-ChildItem -Recurse -Include "*.sql","*.dat" | ForEach-Object { $a = $_.fullname; ( Get-Content $a ) | ForEach-Object { $_ -replace "__SUB__CWD__","<%ORACLE_HOME%>demo\schema" } | Set-Content $a }
    

    * 将 &lt;%ORACLE_HOME%&gt; 替换为您的 Oracle_Home。

    【讨论】:

      猜你喜欢
      • 2015-12-27
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多