Code covered by the BSD License  

Highlights from
Find and Replace in Files

5.0 | 3 ratings Rate this file 30 Downloads (last 30 days) File Size: 3.79 KB File ID: #42877 Version: 1.1

Find and Replace in Files



14 Aug 2013 (Updated )

Replace the specified text in a list of files with new text.

| Watch this File

File Information

This utility will replace all string matches in the target files with a given string. This is similar to 'Replace all' in the editor, except that it can be used programmatically and on multiple files.

For instance, to replace all occurrences of 'abs' with 'mag':

>> find_and_replace('my_file.m', 'abs', 'mag')

Both the "match" and "replace" inputs can be regular expressions. For instance, we can replace all calls to sqrt(...) with my_sqrt(...), keeping the function's argument by using regular expressions.

>> find_and_replace(file_names, 'sqrt\((.*?)\)', 'my_sqrt\($1\)');

For more examples:

>> help find_and_replace;

Some knowledge of regular expressions is helpful, but not required, to use this tool. See 'Regular Expressions' in MATLAB's documentation.


This file inspired Strrepfile.

Required Products MATLAB
MATLAB release MATLAB 8.1 (R2013a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)

Very simple and absolute perfect code.

30 May 2015 Adam Danz

Adam Danz (view profile)

Easy to read, straight-forward coding. Thanks.

17 Dec 2014 Mazi

Mazi (view profile)

great. Thanks!

14 Aug 2013 1.1

Updated trademarks.

Contact us