FAQ
hi all,

i need to format a file using the sed command on windows .

For example iam running this command in my comman prompt of win xp.

D:\sample> sed "s/REM //" sample.sql

'sed' is not recognized as an internal or external command,
operable program or batch file.

Search Discussions

  • Michael Garfield Sørensen at May 15, 2009 at 6:17 am
    http://gnuwin32.sourceforge.net/packages/sed.htm = Sed for Windows

    Works like a charm:

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\>type sample.sql
    REM SELECT * FROM DUAL;

    C:\>which sed
    C:\Program Files\GnuWin32\bin\sed.EXE

    C:\>sed "s/REM //" sample.sql
    SELECT * FROM DUAL;

    HTH

    Michael Garfield Sørensen, CeDeT

    Quoting Niall Litchfield :
    sed is a unix command line tool. You can get various replacements using
    cygwin or others - if sed is a gnu utility there will likely be a windows
    binary for it, or you can reformulate your problem as a business problem
    rather than a technology issue - for example I need to remove all
    occurrences of a string from a file, preferably using the command line. I'd
    just use ctrl-h in write to do string replacement in a text file fwiw.

    Niall

    On Fri, May 15, 2009 at 6:35 AM, Mohammed Mehraj hussain <
    mhdmehraj_at_gmail.com> wrote:
    hi all,

    i need to format a file using the sed command on windows .

    For example iam running this command in my comman prompt of win xp.

    D:\sample> sed "s/REM //" sample.sql

    'sed' is not recognized as an internal or external command,
    operable program or batch file.



    --
    Niall Litchfield
    Oracle DBA
    http://www.orawin.info
    --
    http://www.freelists.org/webpage/oracle-l
  • Howard Latham at May 15, 2009 at 7:03 am
    I have often wondered why windows has such a limited set of commands for an
    Enterprise product.

    2009/5/15 Michael Garfield Sørensen
    http://gnuwin32.sourceforge.net/packages/sed.htm = Sed for Windows

    Works like a charm:
    ------------------------------------------------------------------
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\>type sample.sql
    REM SELECT * FROM DUAL;

    C:\>which sed
    C:\Program Files\GnuWin32\bin\sed.EXE

    C:\>sed "s/REM //" sample.sql
    SELECT * FROM DUAL;
    ------------------------------------------------------------------

    HTH
    Michael Garfield Sørensen, CeDeT



    Quoting Niall Litchfield :

    sed is a unix command line tool. You can get various replacements using
    cygwin or others - if sed is a gnu utility there will likely be a windows
    binary for it, or you can reformulate your problem as a business problem
    rather than a technology issue - for example I need to remove all
    occurrences of a string from a file, preferably using the command line.
    I'd
    just use ctrl-h in write to do string replacement in a text file fwiw.

    Niall

    On Fri, May 15, 2009 at 6:35 AM, Mohammed Mehraj hussain <
    mhdmehraj_at_gmail.com> wrote:

    hi all,
    i need to format a file using the sed command on windows .

    For example iam running this command in my comman prompt of win xp.

    D:\sample> sed "s/REM //" sample.sql

    'sed' is not recognized as an internal or external command,
    operable program or batch file.



    --
    Niall Litchfield
    Oracle DBA
    http://www.orawin.info

    --
    http://www.freelists.org/webpage/oracle-l

    --
    Howard A. Latham

    --
    http://www.freelists.org/webpage/oracle-l
  • Mohammed Mehraj hussain at May 15, 2009 at 7:19 am
    hi Michael,
    Here my scenario is also like that which you have  mentioned bellow.
    this is my entry in the batch file .
    first we are creating the sql commands from a index file, and then we
    are formatting that index file by removing all the rem etc.

    imp system/manager file=emp.dmp fromuser=scott touser=hr
    indexfile=objects.sql log=objects.log 2>&1 | %TEE% -a %LOGFILE%

    rem -----------------------------------------------------------------------------

    rem format the objects.sql file to obj.sql

    rem -----------------------------------------------------------------------------

    del obj.sql 2>&1 | %TEE% -a %LOGFILE%

    sed "s/REM //" objects.sql | sed "/rows/d"  | sed -e "s/#.*//" -e
    "/^$/ d"  |sed "s/CONNECT %OraSchemaOwner%//"  | sed "1a spool
    obj.log" | sed "$a\ " | sed "$a\  spool off" | sed "$a\ exit;" >>
    obj.sql 2>&1 | %TEE% -a %LOGFILE%

    my case is in the index file a a command is created like the below one

    REM ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT

    REM sysdate
    REM

    REM

    REM

    REM );

    REM ... 260000 rows

    it is formatting into

    ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT

    sysdate

    );

    when this command runs,it is comming like this

    SQL> ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT

    2 sysdate
    3

    SQL>
    SQL>
    SQL> );

    SP2-0042: unknown command ") " - rest of line ignored.

    AND MY REST OF THE COMMANDS IN THE BATCH FILE IS ABORTED..

    so i need to include a proper formatting command to ignore the lines
    in-between this one

    ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT

    sysdate

    );

    and need to merge with the );

    plz suggest some commands to do the above task which i need to include in this

    sed "s/REM //" objects.sql | sed "/rows/d" | sed -e "s/#.*//" -e
    "/^$/ d" |sed "s/CONNECT %OraSchemaOwner%//" | sed "1a spool
    obj.log" | sed "$a\ " | sed "$a\ spool off" | sed "$a\ exit;" >>
    obj.sql 2>&1 | %TEE% -a %LOGFILE%

    Thanks and Regards,
    Mohammed

    On Fri, May 15, 2009 at 11:47 AM, Michael Garfield Sørensen
    wrote:
    http://gnuwin32.sourceforge.net/packages/sed.htm = Sed for Windows

    Works like a charm:
    ------------------------------------------------------------------
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\>type sample.sql
    REM SELECT * FROM DUAL;

    C:\>which sed
    C:\Program Files\GnuWin32\bin\sed.EXE

    C:\>sed "s/REM //" sample.sql
    SELECT * FROM DUAL;
    ------------------------------------------------------------------

    HTH
    Michael Garfield Sørensen, CeDeT


    Quoting Niall Litchfield :
    sed is a unix command line tool. You can get various replacements using
    cygwin or others - if sed is a gnu utility there will likely be a windows
    binary for it, or you can reformulate your problem as a business problem
    rather than a technology issue - for example I need to remove all
    occurrences of a string from a file, preferably using the command line. I'd
    just use ctrl-h in write to do string replacement in a text file fwiw.

    Niall

    On Fri, May 15, 2009 at 6:35 AM, Mohammed Mehraj hussain <
    mhdmehraj_at_gmail.com> wrote:
    hi all,

    i need to format a file using the sed command on windows .

    For example iam running this command in my comman prompt of win xp.

    D:\sample> sed "s/REM //" sample.sql

    'sed' is not recognized as an internal or external command,
    operable program or batch file.



    --
    Niall Litchfield
    Oracle DBA
    http://www.orawin.info
    --
    http://www.freelists.org/webpage/oracle-l
  • Howard Latham at May 15, 2009 at 9:22 am
    you can of course suppress almost all the extraneous output from SQLPLUS

    try

    SET FEEDBACK 0

    SET ECHO 0FF

    SET VERIFY OFF

    2009/5/15 Mohammed Mehraj hussain
    hi Michael,
    Here my scenario is also like that which you have mentioned bellow.
    this is my entry in the batch file .
    first we are creating the sql commands from a index file, and then we
    are formatting that index file by removing all the rem etc.

    imp system/manager file=emp.dmp fromuser=scott touser=hr
    indexfile=objects.sql log=objects.log 2>&1 | %TEE% -a %LOGFILE%

    rem
    -----------------------------------------------------------------------------
    rem format the objects.sql file to obj.sql
    rem
    -----------------------------------------------------------------------------

    del obj.sql 2>&1 | %TEE% -a %LOGFILE%

    sed "s/REM //" objects.sql | sed "/rows/d" | sed -e "s/#.*//" -e
    "/^$/ d" |sed "s/CONNECT %OraSchemaOwner%//" | sed "1a spool
    obj.log" | sed "$a\ " | sed "$a\ spool off" | sed "$a\ exit;" >>
    obj.sql 2>&1 | %TEE% -a %LOGFILE%


    my case is in the index file a a command is created like the below one

    REM ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT
    REM sysdate
    REM
    REM
    REM
    REM );
    REM ... 260000 rows

    it is formatting into

    ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT
    sysdate



    );

    when this command runs,it is comming like this


    SQL> ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT
    2 sysdate
    3
    SQL>
    SQL>
    SQL> );
    SP2-0042: unknown command ") " - rest of line ignored.

    AND MY REST OF THE COMMANDS IN THE BATCH FILE IS ABORTED..
    so i need to include a proper formatting command to ignore the lines
    in-between this one

    ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT
    sysdate



    );

    and need to merge with the );


    plz suggest some commands to do the above task which i need to include in
    this

    sed "s/REM //" objects.sql | sed "/rows/d" | sed -e "s/#.*//" -e
    "/^$/ d" |sed "s/CONNECT %OraSchemaOwner%//" | sed "1a spool
    obj.log" | sed "$a\ " | sed "$a\ spool off" | sed "$a\ exit;" >>
    obj.sql 2>&1 | %TEE% -a %LOGFILE%


    Thanks and Regards,
    Mohammed


    On Fri, May 15, 2009 at 11:47 AM, Michael Garfield Sørensen
    wrote:
    http://gnuwin32.sourceforge.net/packages/sed.htm = Sed for Windows

    Works like a charm:
    ------------------------------------------------------------------
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\>type sample.sql
    REM SELECT * FROM DUAL;

    C:\>which sed
    C:\Program Files\GnuWin32\bin\sed.EXE

    C:\>sed "s/REM //" sample.sql
    SELECT * FROM DUAL;
    ------------------------------------------------------------------

    HTH
    Michael Garfield Sørensen, CeDeT


    Quoting Niall Litchfield :
    sed is a unix command line tool. You can get various replacements using
    cygwin or others - if sed is a gnu utility there will likely be a
    windows
    binary for it, or you can reformulate your problem as a business problem
    rather than a technology issue - for example I need to remove all
    occurrences of a string from a file, preferably using the command line.
    I'd
    just use ctrl-h in write to do string replacement in a text file fwiw.

    Niall

    On Fri, May 15, 2009 at 6:35 AM, Mohammed Mehraj hussain <
    mhdmehraj_at_gmail.com> wrote:
    hi all,

    i need to format a file using the sed command on windows .

    For example iam running this command in my comman prompt of win xp.

    D:\sample> sed "s/REM //" sample.sql

    'sed' is not recognized as an internal or external command,
    operable program or batch file.



    --
    Niall Litchfield
    Oracle DBA
    http://www.orawin.info
    --
    http://www.freelists.org/webpage/oracle-l

    --
    Howard A. Latham

    --
    http://www.freelists.org/webpage/oracle-l
  • Michael Garfield Sørensen at May 15, 2009 at 8:20 am
    You can remove the "empty" REM-lines before sed'ing:

    grep -v "^REM *$" objects.sql | sed "s/REM //" | ...

    You need grep (or similar) for that (for example
    http://gnuwin32.sourceforge.net/packages/grep.htm = Grep for Windows)

    Seems to me you may want to look into cygwin OR change to Unix OR go
    the alternate route of Windows Script(ing) -
    http://www.microsoft.com/technet/scriptcenter/default.mspx

    HTH

    Michael Garfield Sørensen, CeDeT

    Quoting Mohammed Mehraj hussain :
    hi Michael,
    Here my scenario is also like that which you have  mentioned bellow.
    this is my entry in the batch file .
    first we are creating the sql commands from a index file, and then we
    are formatting that index file by removing all the rem etc.

    imp system/manager file=emp.dmp fromuser=scott touser=hr
    indexfile=objects.sql log=objects.log 2>&1 | %TEE% -a %LOGFILE%

    rem
    -----------------------------------------------------------------------------
    rem format the objects.sql file to obj.sql
    rem
    -----------------------------------------------------------------------------

    del obj.sql 2>&1 | %TEE% -a %LOGFILE%

    sed "s/REM //" objects.sql | sed "/rows/d"  | sed -e "s/#.*//" -e
    "/^$/ d"  |sed "s/CONNECT %OraSchemaOwner%//"  | sed "1a spool
    obj.log" | sed "$a\ " | sed "$a\  spool off" | sed "$a\ exit;" >>
    obj.sql 2>&1 | %TEE% -a %LOGFILE%


    my case is in the index file a a command is created like the below one

    REM ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT
    REM sysdate
    REM
    REM
    REM
    REM );
    REM ... 260000 rows

    it is formatting into

    ALTER TABLE "HR"."EMPLOYEES" MODIFY ("DATE_TIME" DEFAULT
    sysdate



    );

    when this command runs,it is comming like this
    ...
    --
    http://www.freelists.org/webpage/oracle-l

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouporacle-l @
categoriesoracle
postedMay 15, '09 at 5:35a
activeMay 15, '09 at 9:22a
posts6
users3
websiteoracle.com

People

Translate

site design / logo © 2022 Grokbase