Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Analyzing a text file in mathematica

  1. Jul 10, 2012 #1
    I have a big text file which includes lots of text and data (gaussian log file (it's a scan file))
    and I need to extract some data from it.
    so I need mathematica to search along the textual data and find some strings and put the value in front of that string into a variable.
    can you gimme some ideas how to do that, I have never worked with mathematica on textual data
  2. jcsd
  3. Jul 10, 2012 #2
    any particular reason why you say you "need mathematica" to search this text data file?

    I have never used mathematica, but I doubt is the best choice for parsing a text file.

    I am sure it can be done with mathematica and C and Fortran and Perl and sed and awk...but I this point in my life I would use Python.
  4. Jul 10, 2012 #3
    Post a small example fragment of text, possibly even that you have made up, which is an excellent example of the thing you need to search through. Describe exactly what you want to accomplish with that. Make the example good enough that anyone reasonably skilled would not be able to misunderstand what they were supposed to do, even without needing to ask you more questions and without finishing the project only to discover when giving it back to you to get "well that isn't what I wanted to do, how about this different question."

    With that it should be feasible to write a few lines of code to accomplish your task
  5. Jul 16, 2012 #4
    I almost did the whole thing and mathematica is perfect for this purpose
    I just can't find out how can I tell mathematica to search for a string backward from the current position
    if you guys can help
    I'll be grateful
  6. Jul 16, 2012 #5
    Well, so much for Mathematica being "perfect" for this :tongue: ...in python, this is done with rfind() :biggrin:

    In Mathematica...can you just simply search forwards, from the beginning, several times until you get to the last position of interest and then pick the occurrence of the string with the largest index?

    Like I said, I don't Mathematica...just throwing ideas.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook