\documentclass[a4paper]{article}
\usepackage{pgfplotstable}
\newcount\filecount
\newwrite\cisout
\begin{document}
{
\endlinechar=\newlinechar%
\filecount=1 %
\def\aaa{file number \the\filecount}%
\loop%
\immediate\openout\cisout=data\the\filecount.txt %
\immediate\write\cisout{%
1, 2, \aaa
}%
\immediate\closeout\cisout %
\advance\filecount by 1 %
\ifnum\filecount<5 %
\ifnum\the\filecount=1 \pgfplotstableread[]{data1.txt}{\main} \else\fi
\repeat %
}%
\pgfplotstabletypeset[col sep=comma]{\main}