regardless of extension, i know that the files will be plain text, my
quandary is being able to automatically convert MAC ( \r ) or *NIX ( \n
) files to DOS format, using DOS ( \r\n ).
Is it possible to do this purely in DOS,If not post recommendations
please?
awk "BEGIN{RS=\"[\012\015]\"}{print $0}" foo > bar
where foo is the source file, bar is the target file, and awk is
gawk.exe (free and open source) from
<http://gnuwin32.sourceforge.net/packages/gawk.htm>.
That command line script sets the input record (line) separator to
either CR or LF (note - in DOS, \n is usually CRLF), then as each line
is read in, it prints the line with the default newline marker for the
OS it's running in.
--
T.E.D. (tda...@gearbox.maem.umr.edu)
http://www.textpad.com/add-ons/files/utilities/convert.zip
Convert 3 programs to batch convert files between DOS, MAC and UNIX. For
example, type "ToUnix *.HTML" to convert all your DOS & MAC files before
uploading them to your UNIX web server. (56KB)
--
Phil Robyn
University of California, Berkeley
One tool for Mac / *nix / Window
Horst's PBATS - Batch Tools
http://home.mnet-online.de/horst.muc
------------------------------------------------------------------------
CRLF CR/LF handling utility Ver 1.3 (c) 1998 Horst Schaeffer
------------------------------------------------------------------------
DOS expects plain ASCII files to be terminated by a two characters,
a CR+LF (Carriage Return + Line Feed) pair. ASCII files from other
operating systems may have lines terminated by LF only (Unix) or CR
only (Apple Mac).
CRLF.COM checks an ASCII file for line termination, and corrects it
where necessary. Optionally, CRLF.COM will convert files in any of the
three formats to either of the other two, in one pass. It will neither
change nor add to lines that are already correctly terminated for the
format requested.
@echo off
set UFile=%1
set DFile=%2
if "%DFile%" EQU "" set DFile=%UFile%.dos
echo UFN:%Ufile% to %Dfile%
if exist "%Dfile%.old" del %Dfile%.old
if exist "%DFile%" ren %DFile% %Dfile%.old
if not exist "%UFile%" (echo Please enter Filename&goto:EOF)
for /f "tokens=1,* skip=2 delims=]" %%A in ('find /v /n "" "%UFile%"')
do (
echo Processing Line %%A
if "%%B" equ "" (echo.>>o.txt) else (echo %%B>>o.txt)
)
if "%%B" equ "" (echo.>>%DFile%) else (echo %%B>>%DFile%)
)
Yes.
And using SED:
@echo off & setlocal enableextensions
rem UNIX newlines to PC eolns
set source_=C:\_M\UNIX.TXT
set target_=C:\_M\PC.TXT
sed -e "s/\x0a/\x0d\x0a/" %source_% > %target_%
endlocal & goto :EOF
In fact, any "dummy" sed conversion will do:
sed -e "s/ / /" %source_% > %target_%
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
I find that in some files, the conversion works, then in others i end
up with a file which has nothing but blank lines on it...is anyone
familiar with this error?
It's never failed for me. What are you using for awk? What kinds of
files fail?
--
T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.