Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

COMBINING TWO TEXT FILES

$
0
0
Hi all..i am working with matlab & octave...Hence the code must be optimized in both Matlab & Octave..I had tried to combine both text files using these applications..I am not getting proper output...

this is my code:
clc;clear all;close all;
m=0;n=0;MVal=0;SVal=0;Mcount=0;Scount=0;Acount=0;l count=0;lscount=0;Countnew=0;
Astring=cellstr('Attempt');
[IPFILENAME, ippathname] = uigetfile('*.txt','Select MDump File');
[IP1FILENAME, ip1pathname] = uigetfile('*.txt','Select Sdump File');
[OP1FILENAME, op1pathname] = uigetfile('*.txt','Select Combdump File');
inputid=fopen(fullfile(ippathname,IPFILENAME),'r+' );
inputid1=fopen(fullfile(ip1pathname,IP1FILENAME),' r+');
outputid=fopen(fullfile(op1pathname,OP1FILENAME),' w+');
while (feof(inputid)==0)
getline=fgets(inputid);
m=m+1;
MVal=MVal+1;
if isequal(getline(1,1),'A')
Mcount=Mcount+1;
Masterscan=textscan(getline,'%s%d%s%s%f','delimite r',';');
Ano=Masterscan{2};
for pageno=1:10
if (isequal(Astring,Masterscan{1}) && (isequal(pageno,Ano)))
m1(pageno)=m;
m=0;
endif
endfor
endif
if isequal(Mcount,Ano)
lcount=lcount+1;
endif
clear(getline);
endwhile
while (feof(inputid1)==0)
getipline=fgets(inputid1);
n=n+1;
SVal=SVal+1;
if isequal(getipline(1,1),'A')
Scount=Scount+1;
Slavescan=textscan(getipline,'%s%d%s%s%f','delimit er',';');
Asno=Slavescan{2};
for Spageno=1:10
if (isequal(Astring,Slavescan{1}) && (isequal(Spageno,Asno)))
n1(Spageno)=n;
n=0;
endif
endfor
endif
if isequal(Scount,Asno)
lscount=lscount+1;
endif
clear(getipline);
endwhile
fseek(inputid,0,'bof');
fseek(inputid1,0,'bof');
Total=MVal+SVal;
for iteration=1:Total
Filestring=fgets(inputid);
Subfilestring=fgets(inputid1);
[rownew colnew]=size(Subfilestring);
for Attcount=1:Mcount
if isequal(Filestring(1,1),'A') || isequal(Subfilestring(1,1),'A')
Mscan=textscan(Filestring,'%s%d%s%s%f','delimiter' ,';');
Sscan=textscan(Subfilestring,'%s%d%s%s%f','delimit er',';');
fprintf(outputid,'%s%d%s%s%f\n',Filestring);
endif
if (isequal(Astring,Sscan{1}) && isequal(Masterscan{2},Slavescan{2}) && isequal(Astring,Mscan{1}))
Diff=Mscan{5}-Sscan{5};
endif
endfor
for indatt=1:m1(Attcount)
if ~(isequal(Filestring(1,1),'A')) || ~(isequal(Subfilestring(1,1),'A'))
Mscan=textscan(Filestring,'%s%f%f%f%f%f%f%f%f%f%f% d%f%f%f%f%d%d%d','delimiter',';');
Sscan=textscan(Subfilestring,'%s%f%f%f%f%f%f%f%f%f %f%d%f%f%f%f%d%d%d','delimiter',';');
Stime=Sscan{2};
Snewtime=Diff+Stime;
fprintf(outputid,'%s%f%f%f%f%f%f%f%f%f%f%d%f%f%f%f %d%d%d\n',Filestring);
fprintf(outputid,'%s%f%f%f%f%f%f%f%f%f%f%df%f%f%f% d%d%d\n',Subfilestring);
endif
endfor
endfor
fclose(outputid);
fclose(inputid1);
fclose(inputid);

I want to get 'Attempt' word from both text files..Then number of the attempt like 1 to 10..I should compare both Attempt and number from both files and i should combine..the lines below this attempt in both text file in combined file..I am failing in this attempt..Kindly help.

Viewing all articles
Browse latest Browse all 2703

Latest Images

Trending Articles



Latest Images