0

In https://oracle-base.com/articles/misc/install-sample-schemas. Tim Hall proposes the following command (once positioned in a particular directory) to replace the string __SUB__CWD__ by the name of the current directory in sql files and dat files:

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

How can adapt this command for Windows? Even if the name of directory is constant (ex: C:\app\soutou\product\18.0.0\dbhomeXE\demo\schema). I am not a user of Perl (Oracle dev)

brian d foy
  • 129,424
  • 31
  • 207
  • 592

2 Answers2

2

If you install Strawberry Perl on your windows box this command should just work from the cmd.com shell

perl -i.bak -MCwd -pe"BEGIN{ $cwd = cwd; @ARGV = map glob, @ARGV; } s#__SUB__CWD__#$cwd#g" *.sql *\*.sql *\*.dat
ikegami
  • 367,544
  • 15
  • 269
  • 518
JGNI
  • 3,933
  • 11
  • 21
  • Thanks but with Active Perl this command returns `Can't find string terminator "'" anywhere before EOF at -e line 1.` – Christian Soutou May 30 '19 at 09:10
  • 1
    It might be a long shot, but I remember `cmd.exe` having problems with single quotes. Try replacing them with double quotes: `perl -MCwd -p -i.bak -e "BEGIN{ $cwd = cwd } s#__SUB__CWD__#$cwd#g" *.sql *\*.sql *\*.dat` – truth May 30 '19 at 09:32
  • Thanks it produces now `Can't open *.sql: Invalid argument. Can't open *\*.sql: Invalid argument. Can't open *\*.dat: Invalid argument.` – Christian Soutou May 30 '19 at 09:45
  • @ChristianSoutou See also [this question](https://stackoverflow.com/q/56354760/2173773) – Håkon Hægland May 30 '19 at 10:31
  • @Hakon Haegland, thanks you're right,it works with a single file name (as test.sql instead of *.sql). I'm gonna try with Cygwin – Christian Soutou May 30 '19 at 10:35
  • Updated line so it should now expand file globs – JGNI May 30 '19 at 11:48
  • It works with Cygwin, to avoid the string (/cygdrive/C) coming from the path, I adjusted the original command with the path of the Oracle directory. `perl -p -i.bak -e 's#__SUB__CWD__#'C:/oracle_directory...'#g' *.sql */*.sql */*.dat` – Christian Soutou May 30 '19 at 11:57
0

For Oracle RDBMS on Windows you can use insteat of the perl method :

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 }

* replace <%ORACLE_HOME%> with your Oracle_Home.

Ryan M
  • 18,333
  • 31
  • 67
  • 74