LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-20-2011, 11:58 AM   #1
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Rep: Reputation: Disabled
Help translating code from Linux to OSX?


Hello,

I have the following code:
Code:
#!/bin/bash 

function dx {
python /home/joey/dxTuber/MOD_dxTuber_cmd.py "$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:
Code:
mh320m01:DA_R02 janickij$ ./MOD_Loop_Tuber_Script.sh 
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?

Thanks.
 
Old 07-20-2011, 12:05 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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:
Code:
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,
 
Old 07-21-2011, 08:45 AM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
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.
 
Old 07-22-2011, 01:13 AM   #4
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
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. :<
 
Old 07-25-2011, 02:43 PM   #5
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

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

Code:
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?

Last edited by jdmResearch; 07-25-2011 at 02:44 PM.
 
Old 07-25-2011, 02:48 PM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Is there any reason why you read twice and not both variables in a single read?
 
Old 07-25-2011, 02:54 PM   #7
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
I'm sorry, I don't think I understand your question.

I have these files:
0-protein.dx
0-water.dx
1-protein.dx
1-water.dx
2-protein.dx
2-water.dx
...etc....etc...

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.
 
Old 07-25-2011, 03:55 PM   #8
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Oh sorry, I see the purpose of reading twice now. In your line the do must follow the condition I think:
Code:
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.

Last edited by Reuti; 07-25-2011 at 04:01 PM. Reason: Emphasize syntax
 
Old 07-26-2011, 09:34 AM   #9
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
Well, the ls command worked just as well as find. However, the program still isn't terminating properly.
 
Old 07-26-2011, 11:28 AM   #10
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
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.

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Translating / localising Linux to a new language professorsnapper Linux - General 4 02-23-2011 10:44 AM
Replacing OSX with Linux? No I do not wish to Triple boot OSX, Linux and Windows. Seph64 Linux - General 10 02-06-2011 03:35 PM
newbie needs help translating linux tech speak shadowbox12 Linux - Virtualization and Cloud 2 05-17-2010 11:30 PM
translating C software from Win to Linux altella Programming 7 07-04-2007 04:42 PM
LXer: Linux: Translating Kernel Documentation LXer Syndicated Linux News 0 06-11-2007 01:31 PM


All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration