In the attributes of a CodeBlock element, you can specify an file to be included and the start and end lines using attributes:
CodeBlock
include
startFrom
endAt
Demonstration: Using pandoc-codeblock-include-sample.txt as input gives output file in pdf (use lorem content).