How to preserve file format when using SED

View: New views
7 Messages — Rating Filter:   Alert me  

How to preserve file format when using SED

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I decided to try SED to find and replace a string in my file, however
the command completely messes up my original format.

I used the following command:
C:\Progra~1\GnuWin32
\bin\sed.exe  "s/APP_CONFIG/Substitute_CFG_DB_Name/g"
c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql

How do I preserve the original formatting inside the file?

I was looking for the options, but didn't see any.



Re: How to preserve file format when using SED

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 28 Oct 2008 20:43:27 -0000, "AllaGelfand" <allagelfand@...>
wrote:

>I decided to try SED to find and replace a string in my file, however
>the command completely messes up my original format.
>
C:\Progra~1\GnuWin32\bin\sed.exe  "s/APP_CONFIG/Substitute_CFG_DB_Name/g"
c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql >newfile.sql

>How do I preserve the original formatting inside the file?

It doesn't change the formatting - try the above with >newfile.sql on the
end and examine the new file.  Is that ok?

Re: How to preserve file format when using SED

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I ran the command again using the following syntax:
 
C:\PROGRA~1\GnuWin32\bin>sed.exe -i "s/APP_CONFIG/Substitute_CFG_DB_Name/g" c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql >newfile.sql
 
Attached is the outcome file- format is completely messed up


--- On Tue, 10/28/08, foxidrive <foxidrive@...> wrote:

From: foxidrive <foxidrive@...>
Subject: Re: [BATCH WORLD] How to preserve file format when using SED
To: batchworld@...
Date: Tuesday, October 28, 2008, 4:57 PM






On Tue, 28 Oct 2008 20:43:27 -0000, "AllaGelfand" <allagelfand@ yahoo.com>
wrote:

>I decided to try SED to find and replace a string in my file, however
>the command completely messes up my original format.
>
C:\Progra~1\ GnuWin32\ bin\sed.exe "s/APP_CONFIG/ Substitute_ CFG_DB_Name/ g"
c:\FDSSP_CLM005_ EDI_CLAIM_ SELECT.sql >newfile.sql

>How do I preserve the original formatting inside the file?

It doesn't change the formatting - try the above with >newfile.sql on the
end and examine the new file. Is that ok?
 














     

[Non-text portions of this message have been removed]


Re: How to preserve file format when using SED

by Karl M. Bernard-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I can't see the output, but it may be that sed is outputting the text with a
Unix-style <lf>. If this is the case, the easiest fix is to pipe the output
through UNIX2DOS (part of the CygUtils) before redirecting to the output
file. There are some Sed workarounds, but unix2dos is quick and easy, if you
have it.

Karl Bernard

On Wed, Oct 29, 2008 at 8:56 AM, Alla Gelfand <allagelfand@...> wrote:

> I ran the command again using the following syntax:
>
> C:\PROGRA~1\GnuWin32\bin>sed.exe -i "s/APP_CONFIG/Substitute_CFG_DB_Name/g"
> c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql >newfile.sql
>
> Attached is the outcome file- format is completely messed up
>
>
> --- On Tue, 10/28/08, foxidrive <foxidrive@...> wrote:
>
> From: foxidrive <foxidrive@...>
> Subject: Re: [BATCH WORLD] How to preserve file format when using SED
> To: batchworld@...
> Date: Tuesday, October 28, 2008, 4:57 PM
>
>
>
>
>
>
> On Tue, 28 Oct 2008 20:43:27 -0000, "AllaGelfand" <allagelfand@ yahoo.com>
> wrote:
>
> >I decided to try SED to find and replace a string in my file, however
> >the command completely messes up my original format.
> >
> C:\Progra~1\ GnuWin32\ bin\sed.exe "s/APP_CONFIG/ Substitute_ CFG_DB_Name/
> g"
> c:\FDSSP_CLM005_ EDI_CLAIM_ SELECT.sql >newfile.sql
>
> >How do I preserve the original formatting inside the file?
>
> It doesn't change the formatting - try the above with >newfile.sql on the
> end and examine the new file. Is that ok?
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
> ------------------------------------
>
> To Post a message, send it to:   batchworld@...
>
> To Unsubscribe, send a blank message to:
> batchworld-unsubscribe@...! Groups Links
>
>
>
>


[Non-text portions of this message have been removed]


Re: How to preserve file format when using SED

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Basically I see, that it creates a windows-file vs.DOS_file, as when
I open it in Notepad the format disappears, and I have end of line
characters and other characters that I don't need for further
processing:


Should I use a DOS SEd version instead of Windows SED version?


-- In batchworld@..., "Karl Bernard" <karl-bernard@...>
wrote:
>
> I can't see the output, but it may be that sed is outputting the
text with a
> Unix-style <lf>. If this is the case, the easiest fix is to pipe
the output
> through UNIX2DOS (part of the CygUtils) before redirecting to the
output
> file. There are some Sed workarounds, but unix2dos is quick and
easy, if you
> have it.
>
> Karl Bernard
>
> On Wed, Oct 29, 2008 at 8:56 AM, Alla Gelfand <allagelfand@...>
wrote:
>
> > I ran the command again using the following syntax:
> >
> > C:\PROGRA~1\GnuWin32\bin>sed.exe -
i "s/APP_CONFIG/Substitute_CFG_DB_Name/g"
> > c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql >newfile.sql
> >
> > Attached is the outcome file- format is completely messed up
> >
> >
> > --- On Tue, 10/28/08, foxidrive <foxidrive@...> wrote:
> >
> > From: foxidrive <foxidrive@...>
> > Subject: Re: [BATCH WORLD] How to preserve file format when using
SED
> > To: batchworld@...
> > Date: Tuesday, October 28, 2008, 4:57 PM
> >
> >
> >
> >
> >
> >
> > On Tue, 28 Oct 2008 20:43:27 -0000, "AllaGelfand" <allagelfand@
yahoo.com>
> > wrote:
> >
> > >I decided to try SED to find and replace a string in my file,
however
> > >the command completely messes up my original format.
> > >
> > C:\Progra~1\ GnuWin32\ bin\sed.exe "s/APP_CONFIG/ Substitute_
CFG_DB_Name/

> > g"
> > c:\FDSSP_CLM005_ EDI_CLAIM_ SELECT.sql >newfile.sql
> >
> > >How do I preserve the original formatting inside the file?
> >
> > It doesn't change the formatting - try the above with
>newfile.sql on the
> > end and examine the new file. Is that ok?
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> > ------------------------------------
> >
> > To Post a message, send it to:   batchworld@...
> >
> > To Unsubscribe, send a blank message to:
> > batchworld-unsubscribe@...! Groups Links
> >
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>



Re: How to preserve file format when using SED

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 29 Oct 2008 15:27:50 -0000, "AllaGelfand" <allagelfand@...>
wrote:

>Basically I see, that it creates a windows-file vs.DOS_file, as when
>I open it in Notepad the format disappears, and I have end of line
>characters and other characters that I don't need for further
>processing:
>
>
>Should I use a DOS SEd version instead of Windows SED version?

There are free programs that will work in binary mode - Bruce Guthrie's
Change.exe is one that is particularly powerful, though it is not
long-filename-aware.


Here's a modified version of your code that still uses SED.
It's untested, but you could replace the SED line with CHANGE or another
toll that works in binary mode (so doesn't change formatting codes etc).

@echo off
set file="c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql"
cls
:start
set "dbname="
set "replace="
set /p "DBNAME=Please enter Database name: "
if "%DBNAME%"== "" (
echo Must enter a valid database name like
echo APP_CONFIG or APP_WORK or DEV_FACETS.. .
pause
goto :start
)

for %%a in (
APP_CONFIG
APP_WORK
DEV_FACETS
) do if /i "%DBNAME%"=="%%a" set "replace=%dbname%"

if not defined replace echo You entered: "%DBNAME%", try again&goto :start
echo %DBNAME% will be replaced with %replace%

C:\PROGRA~1\GnuWin32\bin\sed.exe "s/%dbname%/%replace%/Ig" %file%>file.sql

move file.sql %file% /y >nul
del file.sql


Re: How to preserve file format when using SED

by AllaGelfand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you very much, I'll try this version immediately.

I actually had something similar crafted..but not as good ;-)

I'll keep you posted!
--- In batchworld@..., foxidrive <foxidrive@...> wrote:

>
> On Wed, 29 Oct 2008 15:27:50 -0000, "AllaGelfand" <allagelfand@...>
> wrote:
>
> >Basically I see, that it creates a windows-file vs.DOS_file, as when
> >I open it in Notepad the format disappears, and I have end of line
> >characters and other characters that I don't need for further
> >processing:
> >
> >
> >Should I use a DOS SEd version instead of Windows SED version?
>
> There are free programs that will work in binary mode - Bruce Guthrie's
> Change.exe is one that is particularly powerful, though it is not
> long-filename-aware.
>
>
> Here's a modified version of your code that still uses SED.
> It's untested, but you could replace the SED line with CHANGE or another
> toll that works in binary mode (so doesn't change formatting codes etc).
>
> @echo off
> set file="c:\FDSSP_CLM005_EDI_CLAIM_SELECT.sql"
> cls
> :start
> set "dbname="
> set "replace="
> set /p "DBNAME=Please enter Database name: "
> if "%DBNAME%"== "" (
> echo Must enter a valid database name like
> echo APP_CONFIG or APP_WORK or DEV_FACETS.. .
> pause
> goto :start
> )
>
> for %%a in (
> APP_CONFIG
> APP_WORK
> DEV_FACETS
> ) do if /i "%DBNAME%"=="%%a" set "replace=%dbname%"
>
> if not defined replace echo You entered: "%DBNAME%", try again&goto
:start
> echo %DBNAME% will be replaced with %replace%
>
> C:\PROGRA~1\GnuWin32\bin\sed.exe "s/%dbname%/%replace%/Ig"
%file%>file.sql
>
> move file.sql %file% /y >nul
> del file.sql
>