importing select lines from external txt file?

Instead of specifying a proper computer language for syntax highlighting in the environments of the minted package, you can use the option text. This will just typeset the input verbatim-like without syntax-highlighting but with the full functionality of the minted package.

In your case, you probably want to do use \inputminted with the firstline and lastline option. Additionally, just give text as first mandatory argument:

\documentclass{article}

\usepackage{minted}
\usepackage{filecontents}

\begin{filecontents*}{\jobname.C}
int main() {
    printf("hello, world");
    return 0;
}
\end{filecontents*}

\begin{document}

\inputminted[firstline=2,lastline=3]{text}{\jobname.C}

\end{document}

enter image description here


Depending on what's the contents of the file, this might be what you want.

\begin{filecontents*}{\jobname.txt}
This is line 1 with \special{characters}
This is line 2 with \special{characters}
This is line 3 with \special{characters}
This is line 4 with \special{characters}
This is line 5 with \special{characters}
This is line 6 with \special{characters}
This is line 7 with \special{characters}
This is line 8 with \special{characters}
This is line 9 with \special{characters}
\end{filecontents*}

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\verblines}{mmm}
 {
  \begin{flushleft}\ttfamily
  \wobbly_verblines:nnn { #1 } { #2 } { #3 }
  \end{flushleft}
 }

\int_new:N \l__wobbly_verblines_index_int
\ior_new:N \g__wobbly_verblines_file_stream

\cs_new_protected:Nn \wobbly_verblines:nnn
 {
  \ior_open:Nn \g__wobbly_verblines_file_stream { #1 }
  \int_zero:N \l__wobbly_verblines_index_int
  \ior_str_map_inline:Nn \g__wobbly_verblines_file_stream
   {
    \int_incr:N \l__wobbly_verblines_index_int
    \int_compare:nT { #2 <= \l__wobbly_verblines_index_int <= #3 } { ##1 \\ }
   }
  \ior_close:N \g__wobbly_verblines_file_stream
 }
\ExplSyntaxOff

\begin{document}

Here are lines 1 to 3
\verblines{\jobname.txt}{1}{3}

Here are lines 2 to 5
\verblines{\jobname.txt}{2}{5}

Here are all the lines
\verblines{\jobname.txt}{0}{100}

\end{document}

The filecontents* environment is used just for making the example self-contained. The last example shows what happens if the arguments are beyond the number of lines in the file.

enter image description here