# Custom line number with listings

I would like to know if it is possible to set custom line numbers in conjunction with the listings package. Please find below a MWE. I'd just like the last line (numbered 8) to appear as e.g. number 500. If not with listings, would you have any other suggestion ?

Thanks and best regards

\documentclass{article}
\usepackage{listings}
\begin{document}

\begin{lstlisting}[basicstyle=\ttfamily, frame=single, columns=fullflexible, keepspaces=true, numbers=left,  stepnumber=1]
Record Length,2.500000e+03,,  -0.001250000000,  -0.76000,
Sample Interval,1.000000e-06,,  -0.001249000000,  -0.74000,
,,,-00.001225000000,  -0.64000,
,,,-00.001224000000,  -0.62000,

...

,,,00.001249000000,   0.78000,
\end{lstlisting}
\end{document}


which produces the following:

\documentclass{article}
\usepackage{listings}
\begin{document}

{\renewcommand\thelstnumber{%
\ifnum\value{lstnumber}=8 5000\else\arabic{lstnumber}\fi}
\begin{lstlisting}[basicstyle=\ttfamily, frame=single,
columns=fullflexible, keepspaces=true, numbers=left,  stepnumber=1]
Record Length,2.500000e+03,,  -0.001250000000,  -0.76000,
Sample Interval,1.000000e-06,,  -0.001249000000,  -0.74000,
,,,-00.001225000000,  -0.64000,
,,,-00.001224000000,  -0.62000,

...

,,,00.001249000000,   0.78000,
\end{lstlisting}}
\end{document}

• Dear David, thank you very much. That was what I was looking for ! – Sergio Oct 3 '16 at 22:28
• BTW, although the original question is correctly solved, and just for my curiosity... Would it be possible, to set at a specific line, a custom number from which all remaining following lines are renumbered accordingly ? – Sergio Oct 3 '16 at 22:48
• @Sergio yes for example you could change the \if to say \ifnum\value{lstnumber}>7\relax \the\numexpr 5008-\value{lstnumber}\relax\else\arabic{lstmumber}\fi (probably:-) – David Carlisle Oct 3 '16 at 22:52