* Re: dos 2 unix
1998-08-04 4:00 dos 2 unix Anji Morris
1998-08-04 4:00 ` Pat Gunn
@ 1998-08-04 4:00 ` Stephen Thompson
1998-08-04 4:00 ` Nick Manka
1998-08-06 4:00 ` Hans Schwengeler
3 siblings, 0 replies; 8+ messages in thread
From: Stephen Thompson @ 1998-08-04 4:00 UTC (permalink / raw)
On Tue, 04 Aug 1998 10:31:37 -0600, Anji Morris <amorri@sandia.gov>
wrote:
>Hi,
>
>I am running Digital Unix (OSF1 alf.sandia.gov V4.0 878 alpha). I
>cannot seem to find a basic utility that comes with most installations
>of unix to convert carriage return/line feeds to new lines (ie. dos2ux,
>dos2unix, dtox). Any ideas?
That is installed with Pathworks
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dos 2 unix
1998-08-04 4:00 dos 2 unix Anji Morris
1998-08-04 4:00 ` Pat Gunn
1998-08-04 4:00 ` Stephen Thompson
@ 1998-08-04 4:00 ` Nick Manka
1998-08-06 4:00 ` Hans Schwengeler
3 siblings, 0 replies; 8+ messages in thread
From: Nick Manka @ 1998-08-04 4:00 UTC (permalink / raw)
In article <35C73769.9BC50362@sandia.gov>,
Anji Morris <amorri@sandia.gov> writes:
> Hi,
>
> I am running Digital Unix (OSF1 alf.sandia.gov V4.0 878 alpha). I
> cannot seem to find a basic utility that comes with most installations
> of unix to convert carriage return/line feeds to new lines (ie. dos2ux,
> dos2unix, dtox). Any ideas?
Look into tr (1).
--
If you don't have 64 bits, you're not playing with a full DEC.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dos 2 unix
1998-08-04 4:00 dos 2 unix Anji Morris
@ 1998-08-04 4:00 ` Pat Gunn
1998-08-04 4:00 ` John Wilson
1998-08-04 4:00 ` Stephen Thompson
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Pat Gunn @ 1998-08-04 4:00 UTC (permalink / raw)
Anji Morris wrote:
>
> Hi,
>
> I am running Digital Unix (OSF1 alf.sandia.gov V4.0 878 alpha). I
> cannot seem to find a basic utility that comes with most installations
> of unix to convert carriage return/line feeds to new lines (ie. dos2ux,
> dos2unix, dtox). Any ideas?
Fortunately, it's fairly trivial to write such programs. Something
along the lines of the following should do the trick. Note that
this is just off the top of my head, and might not work without a
bit of debugging.
#include <fcntl.h>
#include <sys/types.h>
#define CHAR1 '\r' /* This is the one I'm not sure about.
DOS text files use both CR and NL to
indicate end of line. I think Unix only
uses newlines... */
int main(int argc, char *argv[])
{
FILE *ifile, *ofile;
int mychar;
if(argc != 3)
{
printf("\nUsage: mytranslater infile outfile\n");
exit(1);
}
ifile = fopen(argv[1],"rb"); /* Open our input file */
if(ifile == NULL)
{
printf("Cannot open file %s: error %d\n", argv[1], errno);
exit(1);
}
ofile = fopen(argv[2],"wb+"); /* Open our output file */
if(ofile == NULL)
{
printf("Cannot open file %s: error %d\n", argv[2], errno);
exit(1);
}
while(mychar = fgetc(ifile))
{
if(mychar == EOF)
break;
if(mychar == 'CHAR1')
continue; /* Diddle with logic here to go the other way */
fputc(ofile,mychar);
}
fclose(ofile);
fclose(ifile);
exit(1);
}
--
---------------------------------------------------
Pat Gunn, moderator:comp.sys.newton.announce
comoderator:comp.os.os2.moderated
"You can always judge a man by the quality of his enemies." -- Dr Who
http://junior.apk.net/~qc
------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dos 2 unix
1998-08-04 4:00 ` Pat Gunn
@ 1998-08-04 4:00 ` John Wilson
1998-08-08 4:00 ` Pat Gunn
0 siblings, 1 reply; 8+ messages in thread
From: John Wilson @ 1998-08-04 4:00 UTC (permalink / raw)
In article <35C7A9C0.267@ibm.net>, Pat Gunn <pgunn01@ibm.net> wrote:
>#define CHAR1 '\r' /* This is the one I'm not sure about.
[...]
>while(mychar = fgetc(ifile))
> {
> if(mychar == EOF)
> break;
> if(mychar == 'CHAR1')
> continue; /* Diddle with logic here to go the other way */
> fputc(ofile,mychar);
> }
Careful, you've fallen victim to the common misconception (unfortunately
shared by C-Kermit) that converting from a regular ASCII file to a UNIX text
file requires removing *all* CRs, whereas in fact you only want to remove
CRs that immediately preceed LFs. This program will screw up files that
use CR for overprinting.
I've got a couple of quicky DOS programs to do the conversion correctly at
http://www.dbit.com/pub/ibmpc/util/addcr.com and .../remcr.com, unfortunately
they're filters so they're a bit cumbersome to use, but anyway the above
program would work if you searched for a CR/LF sequence and replaced *that*
with just LF -- so when you see a CR, set a flag instead of writing (or not
writing) anything out, and then next time through the loop, check the flag
and write the CR out after all if the current char is not LF (then clear
the flag, either way). Ah, also get rid of the single quotes around CHAR1.
John Wilson
D Bit
^ permalink raw reply [flat|nested] 8+ messages in thread
* dos 2 unix
@ 1998-08-04 4:00 Anji Morris
1998-08-04 4:00 ` Pat Gunn
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Anji Morris @ 1998-08-04 4:00 UTC (permalink / raw)
Hi,
I am running Digital Unix (OSF1 alf.sandia.gov V4.0 878 alpha). I
cannot seem to find a basic utility that comes with most installations
of unix to convert carriage return/line feeds to new lines (ie. dos2ux,
dos2unix, dtox). Any ideas?
TIA,
anji
--
Anji Morris/Unix Systems Admin
CSU Special Projects ,,,
amorri@sandia.gov (0 0)
-------------------------oOO--(_)--OOo-------
Sandia National Labs w 505/844-4082
1515 Eubank Blvd. SE f 505/844-9202
Albuquerque, NM 87123_0745
--------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dos 2 unix
1998-08-04 4:00 dos 2 unix Anji Morris
` (2 preceding siblings ...)
1998-08-04 4:00 ` Nick Manka
@ 1998-08-06 4:00 ` Hans Schwengeler
1998-08-07 4:00 ` dos 2 unix (Try "flip") Jeff Sullivan
3 siblings, 1 reply; 8+ messages in thread
From: Hans Schwengeler @ 1998-08-06 4:00 UTC (permalink / raw)
In article <35C73769.9BC50362@sandia.gov>,
Anji Morris <amorri@sandia.gov> writes:
> Hi,
>
> I am running Digital Unix (OSF1 alf.sandia.gov V4.0 878 alpha). I
> cannot seem to find a basic utility that comes with most installations
> of unix to convert carriage return/line feeds to new lines (ie. dos2ux,
> dos2unix, dtox). Any ideas?
>
> TIA,
>
> anji
>
> --
> Anji Morris/Unix Systems Admin
> CSU Special Projects ,,,
> amorri@sandia.gov (0 0)
> -------------------------oOO--(_)--OOo-------
> Sandia National Labs w 505/844-4082
> 1515 Eubank Blvd. SE f 505/844-9202
> Albuquerque, NM 87123_0745
> --------------------------
>
>
>
Dear Anji,
I found a small shell script which works in most cases:
#! /bin/ksh
# convert dos files to Unix by removing carriage returns.
for f in $@
do
tr -d '\015' <$f >${f}+ && mv -i $f ${f}~ && mv -i ${f}+ $f
done
Yours, hs.
--
===============================================================================
Hans Schwengeler DECNET/SPAN: 20579::48130::SCHWENGELER
Astronomical Institute INTERNET: schweng@astro.unibas.ch
University of Basel schwengeler@urz.unibas.ch
Venusstrasse 7
CH-4102 Binningen PHONE: +41 61 20 55 422
Switzerland FAX: +41 61 20 55 455
===============================================================================
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dos 2 unix (Try "flip")
1998-08-06 4:00 ` Hans Schwengeler
@ 1998-08-07 4:00 ` Jeff Sullivan
0 siblings, 0 replies; 8+ messages in thread
From: Jeff Sullivan @ 1998-08-07 4:00 UTC (permalink / raw)
There is a public domain program that I've been using for years
on various UNIXes. The version I have was written by Rahul Dhesi
and was posted long ago in comp.sources.misc
I found it on ftp.digital.com
See http://ftp.digital.com/cgi-bin/grep-index?flip
I think the one you want is:
/pub/usenet/comp.sources.misc/volume7/flip.Z
It has the advantage of going in both directions:
flip -u convert to UNIX format from DOS
flip -m convert to MS-DOS format
I have a version on DOS and on UNIX (same code).
-Jeff
--
Jeff Sullivan | Compaq Computer Corp | jps@zk3.dec.com
DEC C and C++ | Nashua, NH ZK3-2/2X29 | sullivan@zko.dec.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dos 2 unix
1998-08-04 4:00 ` John Wilson
@ 1998-08-08 4:00 ` Pat Gunn
0 siblings, 0 replies; 8+ messages in thread
From: Pat Gunn @ 1998-08-08 4:00 UTC (permalink / raw)
John Wilson wrote:
>
> In article <35C7A9C0.267@ibm.net>, Pat Gunn <pgunn01@ibm.net> wrote:
> >#define CHAR1 '\r' /* This is the one I'm not sure about.
> [...]
> >while(mychar = fgetc(ifile))
> > {
> > if(mychar == EOF)
> > break;
> > if(mychar == 'CHAR1')
> > continue; /* Diddle with logic here to go the other way */
> > fputc(ofile,mychar);
> > }
>
> Careful, you've fallen victim to the common misconception (unfortunately
> shared by C-Kermit) that converting from a regular ASCII file to a UNIX text
> file requires removing *all* CRs, whereas in fact you only want to remove
> CRs that immediately preceed LFs. This program will screw up files that
> use CR for overprinting.
>
> I've got a couple of quicky DOS programs to do the conversion correctly at
> http://www.dbit.com/pub/ibmpc/util/addcr.com and .../remcr.com, unfortunately
> they're filters so they're a bit cumbersome to use, but anyway the above
> program would work if you searched for a CR/LF sequence and replaced *that*
> with just LF -- so when you see a CR, set a flag instead of writing (or not
> writing) anything out, and then next time through the loop, check the flag
> and write the CR out after all if the current char is not LF (then clear
> the flag, either way). Ah, also get rid of the single quotes around CHAR1.
Overprinting? Hmm... Oh well, I guess it could easily be fixed by
making a flag like LCwasLF.. hmm... Let's see... Oh well. Looks like
you didn't quote the whole thing, and I'm too lazy to go back and
fix it from my previous :) I'll just leave it as an activity
for the reader... Algorythmically, you'd just stick in a
#define LF '\whatever the octal for this is'
short LCwasLF = 0;
At the start, and stick in a
if(mychar == 'LF') {LCwasLF = 1; continue;}
and change
if(mychar == 'CHAR1'){continue;}
to
if((mychar == 'CHAR1') && (LCwasLF) ){LCwasLF = 0;continue;}
and plunk a LCwasLF below that.
--
---------------------------------------------------
Pat Gunn, moderator:comp.sys.newton.announce
comoderator:comp.os.os2.moderated
"You can always judge a man by the quality of his enemies." -- Dr Who
http://junior.apk.net/~qc
------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1998-08-08 4:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-08-04 4:00 dos 2 unix Anji Morris
1998-08-04 4:00 ` Pat Gunn
1998-08-04 4:00 ` John Wilson
1998-08-08 4:00 ` Pat Gunn
1998-08-04 4:00 ` Stephen Thompson
1998-08-04 4:00 ` Nick Manka
1998-08-06 4:00 ` Hans Schwengeler
1998-08-07 4:00 ` dos 2 unix (Try "flip") Jeff Sullivan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox