I am just experimenting with a couple (about 50 or more) of simple text files, inputting them into a collection to be printed. My first problem, getting the first line printed as a heading in bold, was solved with the help of the accepted answer to another question (https://tex.stackexchange.com/a/385940/159816), which I simplified for my needs.
But I could find no way to get this same line into the toc, which I would like to put into the PDF with the \tableofcontents macro. If the listings package doesn't have the "hook" for that, maybe there is another possibility. I usually use LuaLaTeX, by the way.
Here is my code so far, with two example textfiles.
\documentclass{article}
\usepackage{forloop}
\usepackage{listings}
\newcounter{ct}
\pagestyle{empty}
\makeatletter
\lst@AddToHook{OutputBox}{\lst@boldline}
\let\lst@boldline\relax
\newcommand\lstboldline{%
\def\lst@boldline{\ifnum\lst@lineno=1 \bfseries\fi}}
\makeatother
\begin{filecontents*}{1.txt}
First Line of First Text
Rest of First text Rest of First text Rest of First text Rest of First text Rest of First text
Rest of First text Rest of First text
Rest of First text
Rest of First text Rest of First text
Rest of First text Rest of First text Rest of First text
Rest of First text Rest of First text
\end{filecontents*}
\begin{filecontents*}{2.txt}
First Line of Second Text
Rest of Second text Rest of Second text Rest of Second text Rest of Second text Rest of Second text
Rest of Second text Rest of Second text
Rest of Second text
\end{filecontents*}
\begin{document}
\large
\forloop{ct}{1}{\value{ct} < 3}%
{%
\lstboldline
\lstinputlisting[basicstyle=\sffamily\slshape,
breaklines,
breakautoindent=false,
breakindent=0pt,
breakatwhitespace=true,
columns=fullflexible,
language=]{\arabic{ct}.txt}
}% End of the loop, go to next text
\end{document}
