[Tex/LaTex] Using \lstinputlisting to include a file but only certain lines or line ranges

listings

I wanted to tidy up a TeX document and was curious if you can use \lstinputlisting or a similar function to include a certain part of a source-code file.

Example, I have a 500 or so line source file and I want to include just lines 300-400.

Is there a way to do this?

Best Answer

Each "listing" environment understands the firstline and lastline keys:

\lstinputlisting[firstline=300,lastline=500]{file.cc}
Related Question