Search and Replace file

18 views (last 30 days)
Namira
Namira on 28 Jun 2018
Edited: Jonathon Gibson on 28 Jun 2018
I have some 50+ conf files that I am working. I need to find and replace various variable for all these files. For example, I'd like to find the line
Amplitude = 100; and replace it to: Amplitude = 200; for all files.
I've searched in online and found the solution only for one file. I'm looking for a way to do that in matlab. Any ideas?

Accepted Answer

Jonathon Gibson
Jonathon Gibson on 28 Jun 2018
Edited: Jonathon Gibson on 28 Jun 2018
If you're on a Unix system, and currently in the directory with the conf files, you can run from MATLAB:
!sed -i 's/Amplitude = 100;/Amplitude = 200;/g' ./*
Which will check every file in the current directory (./*) for the first regular expression (Amplitude = 100;) and replace it with the second regular expression (Amplitude = 200;). The ! just makes it the same as entering the command directly into the system's terminal.
  5 Comments
Namira
Namira on 28 Jun 2018
Thank you so much. It's working now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!