Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Executing external command with parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129822] Re: Executing external command with parameters
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 16 Feb 2013 01:10:44 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

On 2/15/13 at 1:58 AM, ramiro.barrantes at 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.




  • Prev by Date: Re: Stephen Wolfram's recent blog
  • Next by Date: Re: Obtaining Random LIne from A file
  • Previous by thread: Executing external command with parameters
  • Next by thread: Mathematica quit unexpectedly - Mountain Lion