Glxc = textscan(fidi, '%s', 'Delimiter','|');
Why are you reading the numeric data as strings? Read it as numeric and the operations on finding the desired values then become trivial.
x=cell2mat(textscan(fidi, '', 'Delimiter','|'));
u=unique(x(:,1); % find the unique values in the first column
for i=1:length(u) % over all unique values
dlmwrite('YourdesiredfilenameforUniqueCase(i)',x(x(:,1)==u(i),:)) % write data for each u
end
I don't understand the other request, sorry...