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 ]

Posts: 26
Registered: 9/18/07
Executing external command with parameters
Posted: Feb 15, 2013 1:56 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


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


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

does not work.

How can I do this?

Lastly, I am getting a randomline using mathematica doing:

getRandomLine[file_, n_] :=
Block[{i = RandomInteger[{1, n}], str = OpenRead[file], res},
Skip[str, "String", i];
res = Read[str, Expression];

However, it is very slow so I was going to try with sed.

Thanks in advance,

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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.