I have a txt file which contains a lot of data (in fact it's the result file of a .nb file which I have run on a cluster). I want to use the data to plot some graphs in a new .nb file.
Since there are a lot of data in the txt file, it's a really time-consuming task to copy and paste each desired part to the new .nb file, so I decided to put two markers at the start and at the end of each part of data by printing a special word. For example in the original .nb file, I write Print["start of density data"]
command at the start of density data part, then I print my density function (which shows the data for density as a list), after this I write Print["end of density data"]
. By doing so, I have determined the start and end of my desired part, then I need to write a code which finds the line number of "start of density data"
(for example it's 600) and also the line number of "end of density data"
(for example it's 700).
Now I can write a code to gives me lines 601-699 which contains my desire data. The latter is a straightforward task, but my main problem is how to write a code which finds the line numbers of two markers, I tried Read
and Find
after importing my txt file but they don't give line numbers. Any idea?
I have attached a dummy file here to facilitate answering.
densityFunction
and then you print "end". Instead of printing thedensityFunction
, save its output to a file.Put[densityFunction[arguments], "some file name"]
. To read it laterdensityData = Get["some file name"]
$\endgroup$