Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Executing external command with parameters
Replies: 1   Last Post: Feb 16, 2013 1:08 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bill Rowe

Posts: 1,638
Registered: 3/14/08
Re: Executing external command with parameters
Posted: Feb 16, 2013 1:08 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/15/13 at 1:58 AM, ramiro.barrantes@gmail.com (Ramiro) wrote:

>I would like to get a random line from a file, I know this can be
>done with Mathematica but I am playing with using sed to see if it
>goes faster, say I want to get line 1000


>In mathematica it would be:

><<"! sed -n p1000 filename.txt"

>However, I am trying to put the filename as a variable, say

>filename="hugefile.txt"

>cmd="! sed -n p1000 "<>filename <<cmd

>does not work.

>How can I do this?

Here is how I do something very similar to what you've indicated
you are trying to do

bbedit[filename_String]:=Run["bbedit", "'"<>filename<>"'"]
bbedit[]:=Run["bbedit", "'"<>Directory[]<>"'"]
bbedit[filename_String, switches__]:= Run["bbedit", switches, StringJoin@@{"'",filename,"'"}]

This function runs a command line utility that passes the file
(filename) to my favorite text editor for editing.





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.