Convert UNIX formated text files to DOS formated?

norseman norseman at hughes.net
Wed May 13 02:15:12 CEST 2009


walterbyrd wrote:
> I have about 150 unix formated text files that I would like to convert
> to dos formated.
> 
> I am guessing that I loop though each file in the directory, read each
> line and conver the last character, then save to a file with the same
> name in another directory.
> 
> I am not really sure what I convert the last charactor to.
===================
Subject line says UNIX to DOS

I hope that means you are using a UNIX machine.

addcr.scr
========
#!/bin/bash
#
cat $1 | sed s/$/$'\x0d'/ >$1.cr
#
#            end of file
========
I have utils on MSDOS that add the cr to get the   crlf sequence
I wrote it for use in the rare occasion. (my definition of rare. :)




rmcr.scr
========
#!/bin/sh
# rmcr.scr
# removes <cr> from text files
# Date: Feb. 2004
#   by: SLT
#     : file dressed up Dec. 2004
#
#   a literal <cr> follows first slash following the s.
#
i=$1
i1=${i%%.*}
echo $i1
cat $1 | sed s/^M// >$i1._cr
#
#            end of file
===========
The ^M will needs to be entered at 'type in' time.
In vi  it is done by  pressing CTRL-V  CTRL-M in sequence
DO NOT CUT n PASTE that line!!!
I have never been able to use the $'\x0d' in this file.
The MSDOS programs don not run on Linux, per se.  'Ya Think' :)


crlf    \r \n     x'0D' x'0A'    CTRL-M  CTRL-J
carriage return, line feed    keep the pair in the order shown.



to use in UNIX:

(be in a bash shell)
bash
for f in *.txt; do addcr.scr $f; done    # going to MSDOS

for f in *.txt; do rmcr.scr $f; done     # returning from MSDOS

if you run these on a binary - the binary is destroyed!!!


If you are in MSDOS, I have no help.
Well - see if you can find and download  FILT.EXE (ver 1.0)
   from the 1980 something era
FILT <Enter>  will present the helpfiles
It's what I use.  I set up batch (.BAT) files to expedite my desires.


Best of Luck


Steve



More information about the Python-list mailing list