2

Allow me to be more specific: I have quite a quantity of folder, each of them containing a .txt file. I would like to extract some text from the header of that file to put it in a LaTeX presentation (one presentation per folder).

One problem is the structure of this header: I'ts only few datas lost in hundreds 'spaces', and I have no idea how to select the part I needs.

V                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                I   T34CPT7                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         C   06/02/15  09:38:15                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              AH      0.000000E+0015                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              FZ  T34CPT7                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         FX      0.000000E+00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                FQ      1.000000E+01                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                FM       1    0.000000E+00  

Have someone any idea how to extract a part of this header (for example the 'T34CPT7' part) and use it to fill automatically a field in my LaTeX document ?

Plasmo
  • 21
  • 1
  • Welcome to TeX.SX! This should be possible, but depends heavily on the format of the header. I am not sure if this would be better than with sed or awk, which read those files and create some .tex code which can be input –  Jun 10 '15 at 16:12
  • 2
    My choice would be awk or python as with both it is easy to ignore whitespace. As Christian says, exactly what needs to be done depends upon the structure of these files and how you recognize the "header". This question is probably best diverted to stackoverflow as it is looking more like a programming question than a TeX one. –  Jun 10 '15 at 17:08
  • Using plain tex commands like \openin, \closein and \read you can read and parse files, but it isn't trivial. – John Kormylo Jun 10 '15 at 20:43
  • If it was me, I would use R to load and reformat the data, and Sweave to do this within LaTeX. – vaettchen Jun 11 '15 at 02:58

1 Answers1

3

enter image description here

\documentclass{article}

\newread\zz
\def\extractstuff#1 #2 #3 #4 #5 #6 #7\relax{%
f1=#1, f2=#2, f3=#3, f4=#4, date=#5, time=#6}

\begin{document}

\openin\zz=foo.txt
\read\zz to \tmp
\expandafter\extractstuff\tmp\relax
\closein\zz



\end{document}
David Carlisle
  • 757,742