View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
findreplace

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

3.57143
3.6 | 7 ratings Rate this file 2 Downloads (last 30 days) File Size: 2.77 KB File ID: #9447 Version: 1.0
image thumbnail

findreplace

by

 

25 Dec 2005 (Updated )

This function finds and replaces strings in a text file

| Watch this File

File Information
Description

SYNTAX:

findreplace(file,otext,ntext)
findreplace(file,otext,ntext,match)

file: text file name (with or without path)
otext: text to be replaced (old text)
ntext: replacing text (new text)
match: either (1) for match case or (0) to ignore case. Default value is (1)

Example:

findreplace('sample.txt','Moller','Moler');
findreplace('sample.txt','jake','Jack',0);
findreplace('sample.txt','continue it is','continue its',0);

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
19 Jul 2016 bhavadeep polareddy

Requirement:
1.In file “CBI.m” we have to find a line starting with “InvtrHvLdFrmRtdActvPwrkW =” and copy the entire line and store it into a variable.
2.In file “Master_Copy.m” have to find a line starting with “FrmRtdActvPwrkW =” and replace the entire line with the data that is copied on Point#1.
How can we do this ?

Comment only
20 Mar 2012 Ermes

Ermes (view profile)

Jalla!

17 May 2011 Lu

Lu (view profile)

 
13 Mar 2011 Giuseppe Romano  
01 Jan 2008 Ellis King

The problem with removing '%' comment lines in .m files is caused by the fprintf function using the same character to indicate input. This function can be improved for use with .m files by inserting the additional check inside the 'for' loop, prior to the fprintf call at line 117:

if strcmp(fext, '.m')
line{i} = strrep(line{i},'%','%%');
end

The logic ensures that the comments apply only for .m files.

Otherwise, it works fairly well.

09 Apr 2007 ahmet anýl dindar

I've just used it. I have a *.dat file in which I want to change a specific number. It changes efficiently, but somehow the lines are re-arranged as one after each other horizontally instead of vertically with a small square character. It confuses me te follow the inputs in the files after using find/replace. Therefore, I sugges the author to succed keeping the original file as it was after applying the .m code.

19 Jul 2006 Chengzhou Wang

Hi,

After I ran this script to replace strings of my matlab files, I found that all my comment lines (with '%') are removed, which is not what I want. Can the author check why this is the case?

30 Jan 2006 x y

Great!
We love you!

Contact us