[Thread Prev][Thread Next][Index]

Re: [ferret_users] [Ferret Users] A problem of SHAKEY with Ferret forMac 550



| BTW, when I use a JNL file created by Windows, I have to convert the  
| line end "\r\n" to "\n", or "^M$" to "$". Do you know any good idea  
| to do that? The only method I know is to open it with VI and copy and  
| paste it to a blank file created by VI. That's really a stupid idea.  
| So could you pls give some help?

We talked about this in person yesterday, but it seems the
sed method I suggested didn't work since you are writing
this to the list.  I'm sure you can make sed, awk, ruby, perl, etc.
do the job.  But, I don't know how to do it off the top of my head.

So, I'm attaching a tiny C++ program to get rid of '\n'.

For those who are not familiar with the "newline problem",
a newline is represented differently on different OSes.

               hexadecimal   representation in C language
   Unix/Linux    0a             '\n'
   Windows       0d 0a          '\r' '\n'
   Mac           0d             '\r'

So, to convert a Windows textfile for Mac, you need to
remove '\n' characters.

Ryo

//--- dos2mac.cc -----------
// Compile it by
//
//    $ g++ -o dos2mac  dos2mac.cc
//
// and use it as
//
//    $ ./dos2mac < script-win.jnl > script-mac.jnl
//
// This program is inefficient but is good enough for
// small text files.
//
#include <iostream>
int main()
{
  char c;
  while (std::cin.read(&c,1)) {if (c != '\n') std::cout.write(&c,1);}
}

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement