-   Programming (
-   -   Help translating code from Linux to OSX? (

jdmResearch 07-20-2011 10:58 AM

Help translating code from Linux to OSX?

I have the following code:


function dx {
python /home/joey/dxTuber/ "$protein" "$water"

find -type f -name '*.dx' -printf '%f\n' | sort -n -t _ | while read protein && read water; do dx ; done

So essentially, it finds dx files, sorts them by numbers at the beginning, then performs the dx function I made (loops over all of the #-protein.dx and #-water.dx files).

It works fine when I'm running it on Ubuntu 11.04. However, when I try to run it on OSX, I get the following error:

mh320m01:DA_R02 janickij$ ./
find: illegal option -- t
find: illegal option -- y
find: illegal option -- p
find: illegal option -- e
find: -printf: unknown option

Does anybody have any suggestions?


Snark1994 07-20-2011 11:05 AM

According to this (I don't run OSX) all your options are supported except -printf; perhaps try putting the directory it should search in after "find"? ie:

find . -type f -name '*.dx'
As I said, OSX doesn't seem to support -printf, though it does support -fprintf. So you could either experiment with the -print0 option, or -fprintf to a file and then read it in for the next part of your loop.

Hope this helps,

Reuti 07-21-2011 07:45 AM

The tools in Mac OS X are from BSD and not the GNU ones. E.g sed I compile on my own to get the options Iím used to. You could try to compile and use GNU version.

In the BSD version you must specify a path (i.e. the . Snark1994 used), but in GNU itís optional.

jdmResearch 07-22-2011 12:13 AM

Excellent! Thanks for the help. As an Ubuntu user for half a year, I despise OSX, but I have to make my programs work with OSX because that's what the lab I'm working in uses. :<

jdmResearch 07-25-2011 01:43 PM

I've come across another problem with this. Here's my code now (the extra lines of code (from above) haven't been changed):


find *.dx -print | sort -n -t _ | while read protein && read water; echo $protein $water; do dx ; done
It does everything that I want it to do...It's just not terminating properly. It takes the last 'water' file and keeps trying to run the dx function on them. It'll keep spitting out error messages until the process is killed. The program is outputting *out.dx files, but I wouldn't think that'd interfere.

The echo command shouldn't be causing the problem either, should it?

Anyone know how to properly end this?

Reuti 07-25-2011 01:48 PM

Is there any reason why you read twice and not both variables in a single read?

jdmResearch 07-25-2011 01:54 PM

I'm sorry, I don't think I understand your question.

I have these files:

The function dx takes two arguments, the protein and the water file, to output a new file: #-protein_out.dx.

Do you mean, why isn't it
while read protein water (or something like this?)
instead of
while read protein && read water

I don't know. It worked on linux. It doesn't work on Mac.

Reuti 07-25-2011 02:55 PM

Oh sorry, I see the purpose of reading twice now. In your line the do must follow the condition I think:

ls *.dx | sort -n -t _ | while read protein && read water; do echo $protein $water; dx; done
When all is in the same directory, maybe a find is not needed.

jdmResearch 07-26-2011 08:34 AM

Well, the ls command worked just as well as find. However, the program still isn't terminating properly.

jdmResearch 07-26-2011 10:28 AM

OH. The do echo part of the code is what was screwing it up. I had that in there to test if the find command worked okay on the Mac. Took that out, and it worked fine.


All times are GMT -5. The time now is 07:13 PM.