> 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