2

I have a bunch of tex files in different folders on my system. The goal is to create new tex files (using a template, that has the title page, packages, new commands,...) that combines all the definitions/theorems of the other tex files at a specific place in this template file.

I'm pretty new to linux, so I was wondering which command/set of commands would be the best to use here. So far I used:

$ sed -n '/begin{definition}/,/end{definition}/p' <infile >outfile

which succeeds in extracting the definitions from one file into another.

Someone any suggestions?

tombo
  • 63

1 Answers1

3

If I understand you correctly, you managed to extract the definitions but can't get them inside the template. You can mark the place inside the template where you want to add the definitions with a specific pattern and then use sed or perl to substitute your definitions in place of that pattern.

An even easier way would be to split the template file into 2 files: a file containing everything that must come before the definitions and another for what comes after the definitions and concatenate all 3 files using cat:

cat pre_defs.tex defs.tex post_defs.tex > whole_file.tex
Joseph R.
  • 39,549
  • 1
    Even do something like def_extractor this.tex foo.tex bar.tex | cat pre_defs.tex - post_defs.tex > final.tex, where the def_extractor is something like the sed oneliner above. Oh, the power of Unix. – vonbrand Mar 01 '13 at 18:40
  • Indeed. Gotta love pipes! :) (and the useful use of cat) – Joseph R. Mar 01 '13 at 22:30