Converting Mac ascii to Unix ascii?

Converting Mac ascii to Unix ascii?

Post by Rand » Thu, 11 Jul 2002 07:22:23



We have consultants delivering jsp files in Mac ascii format.  We need
them in Unix ascii format.  Does anyone have a mac to Unix utility or
can someone tell me how to do it using sed?

Thanks

BTW,  Mac ascii files have lines ending in the character CR  or 0D.
Unix of course is CRLF  or ODOA.

Thanks

 
 
 

Converting Mac ascii to Unix ascii?

Post by Rich Tee » Thu, 11 Jul 2002 09:22:00



Quote:> BTW,  Mac ascii files have lines ending in the character CR  or 0D.
> Unix of course is CRLF  or ODOA.

No it isn't: that's the DOS/Windoze way.  UNIX text files just have
0D (\n) at the end of a line.

--
Rich Teer

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net

 
 
 

Converting Mac ascii to Unix ascii?

Post by E. Gibbo » Thu, 11 Jul 2002 09:57:23





>> BTW,  Mac ascii files have lines ending in the character CR  or 0D.
>> Unix of course is CRLF  or ODOA.

>No it isn't: that's the DOS/Windoze way.  UNIX text files just have
>0D (\n) at the end of a line.

ITYM 0x0a (LF) for Unix.  0x0d is Mac, where the OP is coming *from*.

Mentioning '\n' will do nothing but spread confusion: '\n' is the C
language representation for end-of-line, which will map to a different
character (or character*s*), depending on the system.  The translation is
handled by the C library (and only occurs when a file is opened in text
mode).

--Ben

--

 
 
 

Converting Mac ascii to Unix ascii?

Post by Mark Ra » Thu, 11 Jul 2002 10:40:02



>We have consultants delivering jsp files in Mac ascii format.  We need
>them in Unix ascii format.  Does anyone have a mac to Unix utility or
>can someone tell me how to do it using sed?

Is sed a requirement?  tr is easier for this.
tr '\015' '\012' < infile > outfile

Quote:>BTW,  Mac ascii files have lines ending in the character CR  or 0D.

Or \015 if you like octal ;)

Quote:>Unix of course is CRLF  or ODOA.

Nope.  Unix, of course, is LF only, or 0A (or \012).  DOS is CRLF, as
are a number of network protocols (including http).
--

 
 
 

Converting Mac ascii to Unix ascii?

Post by David C » Fri, 12 Jul 2002 06:37:22



> We have consultants delivering jsp files in Mac ascii format.  We need
> them in Unix ascii format.  Does anyone have a mac to Unix utility or
> can someone tell me how to do it using sed?

mac2unix is trivial - just replace CR with LF.  One simple way is to use tr:

        cat infile | tr \\015 \\012 > outfile

If you don't like using tr, a C program to do the same thing is trivial
to write:

     #include <stdio.h>
     #include <stdlib.h>
     #include <errno.h>
     #include <unistd.h>

     int main()
     {
         char    buffer[1000];
         ssize_t bytes_read, i, bytes_written;

         while ((bytes_read = read(0, buffer, 1000)) > 0)
         {
             for(i = 0; i < bytes_read; i++)
             {
                 if (buffer[i] == 13)   /* CR */
                     buffer[i] = 10;    /* LF */
             }

             bytes_written = write(1, buffer, bytes_read);

            if (bytes_written < 0)
             {
                 perror("write failed: ");
                 exit(1);
             }
         }

         if (bytes_read < 0)
         {
             perror("read failed: ");
             exit(1);
         }

         return 0;
     }

Converting to/from DOS format (with CRLF as line-ending) is left as an
exercise for the reader.

-- David

 
 
 

Converting Mac ascii to Unix ascii?

Post by E. Gibbo » Fri, 12 Jul 2002 08:50:17





>> We have consultants delivering jsp files in Mac ascii format.  We need
>> them in Unix ascii format.  Does anyone have a mac to Unix utility or
>> can someone tell me how to do it using sed?

>mac2unix is trivial - just replace CR with LF.  One simple way is to use tr:

>    cat infile | tr \\015 \\012 > outfile

>If you don't like using tr, a C program to do the same thing is trivial
>to write:

That is true: so why didn't you write it the trivial way?  unistd.h??
Why not let C do the buffering?

#include <stdio.h>

#define CR 0x0d
#define LF 0x0a

int main(void)
{
    int c;

    while((c = getchar()) != EOF) {
        if(c == CR)  putchar(LF);
        else         putchar(c);
    }
    return 0;

Quote:}
>     #include <stdio.h>
>     #include <stdlib.h>
>     #include <errno.h>
>     #include <unistd.h>

>     int main()
>     {
>         char    buffer[1000];
>         ssize_t bytes_read, i, bytes_written;

>         while ((bytes_read = read(0, buffer, 1000)) > 0)
>         {
>             for(i = 0; i < bytes_read; i++)
>             {
>                 if (buffer[i] == 13)   /* CR */
>                     buffer[i] = 10;    /* LF */
>             }

>             bytes_written = write(1, buffer, bytes_read);

>        if (bytes_written < 0)
>             {
>                 perror("write failed: ");
>                 exit(1);
>             }
>         }

>         if (bytes_read < 0)
>         {
>             perror("read failed: ");
>             exit(1);
>         }

>         return 0;
>     }

>Converting to/from DOS format (with CRLF as line-ending) is left as an
>exercise for the reader.

>-- David

--
 
 
 

Converting Mac ascii to Unix ascii?

Post by DV-Assisten » Sat, 13 Jul 2002 19:50:11




> > We have consultants delivering jsp files in Mac ascii format.  We need
> > them in Unix ascii format.  Does anyone have a mac to Unix utility or
> > can someone tell me how to do it using sed?

> mac2unix is trivial - just replace CR with LF.  One simple way is to use tr:

>         cat infile | tr \\015 \\012 > outfile

Useless use of cat

Quote:> -- David

Greetings, J"o!

--
sigfault