Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: find and replace string in a text file
Replies: 17   Last Post: May 12, 2013 5:58 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Ondrej

Posts: 19
Registered: 2/3/09
find and replace string in a text file
Posted: Mar 7, 2009 6:38 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi Guys,
can you please give me some advise how can I search and replace a word (string) in a text file using Matlab only (no perl),... I was trying the following but it doesn't work,...
thanks a lot, Ondrej

fid = fopen('118521_1.TXT');

while(~feof(fid))
s = fgetl(fid);
s(find(s=='118520'))='118521'; %% <<< ====
fprintf(fid,'%d',s);
disp(s)
end
fclose(fid);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.