Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Executing external command with parameters

  • To: mathgroup at
  • Subject: [mg129806] Executing external command with parameters
  • From: Ramiro <ramiro.barrantes at>
  • Date: Fri, 15 Feb 2013 01:58:28 -0500 (EST)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:


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,

  • Prev by Date: Re: Finding Maximum without a plot
  • Next by Date: Mathematica quit unexpectedly - Mountain Lion
  • Previous by thread: Wald's SPRT algorithm
  • Next by thread: Re: Executing external command with parameters