input='exportlist.txt';
output='exportlist.bib';


fidIn=fopen(input);
fidOut=fopen(output,'wt');

textIn=textscan(fidIn,'%s','delimiter','\n');
textIn=textIn{1};
for i = 1:length(textIn)
    line=textIn{i};
    
    %Za deklaraci bibliografické položky vložíme automaticky její název,
    %aby se dalo z textu odkazovat. Název položky se skládá z příjmení
    %hlavního autora, následovaného rokem napsání článku (ve formátu YYYY).
    if(~isempty(regexp(line,'@.*'))) 
        numLine=i+1;
        foundName=false;
        foundYear=false;
        author='';
        year='';
        while (~foundName) 
           if ~isempty(regexp(textIn{numLine} ,'author =.*')) %řádek s autorem
              foundName=true;
              leftBracket=regexp(textIn{numLine},'{');
              comma=regexp(textIn{numLine},',');
              comma=comma(1); %Zajímá nás jen první výskyt čárky (za příjmením autora).
              author=textIn{numLine}(leftBracket+1:comma-1);
           end
           numLine=numLine+1;
        end
        while (~foundYear)
            if ~isempty(regexp(textIn{numLine} ,'year =.*')) %řádek s rokem
              foundYear=true;
              leftBracket=regexp(textIn{numLine},'{');
              rightBracket=regexp(textIn{numLine},'}');
              year=textIn{numLine}(leftBracket+1:rightBracket-1);
              try
                 year=num2str(year); %Kdyby matlab chtěl číslo konvertovat na číselný typ...
              end
            end
           numLine=numLine+1;
        end
        line=[line author year ',']; 
    end
    
    %Cislo svazku ma byt tucne.
    if(~isempty(regexp(line,'volume =.*'))) 
        leftBracket=regexp(line,'{');
        rightBracket=regexp(line,'}');
        firstPart=line(1:leftBracket);
        middlePart=line(leftBracket+1:rightBracket-1);
        try
            middlePart=num2str(middlePart); %Kdyby matlab chtěl číslo konvertovat na číselný typ...
        end
        lastPart=line(rightBracket:end);
        line=[firstPart '\textbf{' middlePart '}' lastPart];
    end
    
    fprintf(fidOut, '%s\n', line);
end

fclose(fidOut);
fclose(fidIn);