Can LaTeX natively include only specific expressions from an input file (ignoring the rest)? I am not sure how to best word my question. Below is an example of what I'd like to do.
Situation
For example, let's say I have many files with all kinds of code, but each one shares something in common, a summary environment.
I decide to create a document that contains summaries of all of the other documents. For a meaningful document, I need to get the name of the input file and include only the following code from the input:
\begin{summary}
A bunch of text.
\end{summary}
Here is a sample file structure:
Documents/
JimsAdventures.tex
CrazyGorilla.tex
BrightHorizon.tex
MoonLanding.tex
Summaries.tex <-- includes summaries of all other tex files and their file names
It would be great if Summaries.tex could automatically detect new files in the Documents folder such that it is completely automated (obviously that is a bonus and not really a criterion for the question).
I know this is possible with scripting languages by calling a shell script with the --shell-escape option combined with \immediate\write18 or \include{|myscript.sh}, but is this possible natively in LaTeX?
UPDATE June 30, 2015
Solution based on Werner's suggestion:
LaTeX does support this feature with the catchfilebetweentags package. What it does not support is getting a list of files (e.g. within the same folder) to input automatically (unless the only change between file names is a number: in which case you can use a sequence see Including all files within a directory) .
To avoid using --shell-escape and maintain an OS-independent workflow, it is possible to achieve the same thing by creating a separate file (e.g. Documents.txt) that contains the names (or paths depending on whether you want to reconstruct paths with a macro or not) of the documents (stories). To have Summaries.tex automated, you can reference this file (e.g. Documents.txt) instead of having LaTeX generate it with --shell-escape + external script. Of course, 100% automation would require a system that runs a pre-compilation script that collects all of the tex files you want to include and spits them out into Documents.txt beforehand.

\inputonly part of a file. The main suggestion there would be to use tags andcatchfilebetweentags. – Werner Jun 29 '15 at 22:00standaloneyou can set environments of your choice as standalone environments. – cfr Jun 29 '15 at 22:01--shell-escapeis not ideal for a couple of reasons: (1) It is a security risk. (2) Solution is often platform-specific. – Jonathan Komar Jun 29 '15 at 22:20gawkvia shell escape is no more dangerous than running gawk in any other way. Most of the security risk comes from the possibility of compiling a document from an untrusted source. There is, admittedly, a residual risk in that somebody could hide a shell script, say, in a package which your document loads or in the class it uses. But the majority of the risk lies in compiling random documents from others with shell escape enabled. (2) is, however, true. But so is egreg's point. – cfr Jun 29 '15 at 22:24catchfilebetweentagsseems to be sufficient. (Although I'd like to automate the file inputs to all files in a given folder--but that is not explicitly part of the question) – Jonathan Komar Jun 30 '15 at 07:47