Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13506
| From | Ramiro Barrantes <rbarrant@uvm.edu> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Obtaining Random LIne from A file |
| Date | 2013-02-16 06:07 +0000 |
| Message-ID | <kfn7nt$qaj$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
Hello,
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?
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];
Close[str];
res[[2]]
]
However, it is very slow so I was going to try with sed.Any suggestions?
Thanks in advance,
Ramiro
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
Obtaining Random LIne from A file Ramiro Barrantes <rbarrant@uvm.edu> - 2013-02-16 06:07 +0000
Re: Obtaining Random LIne from A file David Bailey <dave@removedbailey.co.uk> - 2013-02-17 09:08 +0000
Re: Obtaining Random LIne from A file awnl <awnl@gmx-topmail.de> - 2013-02-18 10:59 +0000
Re: Obtaining Random LIne from A file David Bailey <dave@removedbailey.co.uk> - 2013-02-19 06:09 +0000
Re: Obtaining Random LIne from A file Ramiro <ramiro.barrantes@gmail.com> - 2013-02-19 06:09 +0000
Re: Obtaining Random LIne from A file "Kevin J. McCann" <kjm@KevinMcCann.com> - 2013-02-19 23:51 +0000
Re: Obtaining Random LIne from A file awnl <awnl@gmx-topmail.de> - 2013-02-19 23:52 +0000
Re: Obtaining Random LIne from A file David Bailey <dave@removedbailey.co.uk> - 2013-02-19 23:52 +0000
csiph-web