# Print number of lines of an external file

I would like to print in a .tex file the number of lines of some other file (not the content, just how many lines).

For example in the following code I would like to have 3 print in the text

\documentclass{article}

\begin{filecontents}{test.txt}
a
b
c
\end{filecontents}

\begin{document}

Here should be the number of lines in test.txt

\end{document}


This prints 7 not 3 as the file has 7 lines due to comments, but:

\documentclass{article}

\begin{filecontents}{test.txt}
a
b
c
\end{filecontents}

\newcount\zzzlines
\begin{document}

Here should be the number of lines in test.txt

\zzzlines=-1
\openin\zzz=test.txt
\loop
\ifeof\zzz
\else
\repeat
\the\zzzlines

\end{document}


test.txt is

%% LaTeX2e file test.txt'
%% generated by the filecontents' environment
%% from source bb988' on 2019/07/09.
%%
a
b
c

– wasa
Jul 9 '19 at 19:54

With the help of knitr

\documentclass{article}
\begin{document}

test.txt` have 3 lines