Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
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 1 '13 at 18:40
    
Indeed. Gotta love pipes! :) (and the useful use of cat) –  Joseph R. Mar 1 '13 at 22:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.