Here is page \pageref{here}\label{here} \pageref{here}\label{here} can get the page number of the current location, I want to write it into a txt file, but writing directly will report an error, I want to know how to convert this variable so that it can be written into a txt file.
\documentclass{article} \usepackage{zref-abspage,lipsum} \usepackage{fancyhdr} \newwrite\myoutfile \immediate\openout\myoutfile=\jobname-myoutfile.txt \begin{document} \lipsum[1-10] \immediate\write\myoutfile{\pageref{here}\label{here}.} \lipsum[10-12] \end{document} 
grep here foo.auxor similar\immediate\write\myoutfile{\detokenize{\pageref{here}\label{here}.}}\write\myoutfile{\thepage}, but as I said in the first comment, why do you need a special file for this, if you do use\labelthen the information is written to the aux file.