MATLAB: Find specific text in a text file find specific text Hi In the text file below, I want to obtain everything between "|[" and "]|". system component1 |[ b,a,d, w,e,r ]| component2 endsystem so the output is : b,a,d, w,e,r Thanks in advance. Best Answer Please refer to the functions fileread & regexp. Let's assume that the following content "systemcomponent1 |[ b,a,d, w,e,r ]| component2endsystem" is in a text file named textFile.txt then the following code might help you:textChar = fileread("textFile.txt");startIndex = regexp(textChar,'|[');endIndex = regexp(textChar,']|');requiredOutput = textChar(startIndex+1:endIndex-2) Related SolutionsMATLAB: How to change text in textfile with matlab Refer to the documentation of fileread & regexp and Export to Text Data Files with Low-Level I/O.The following code might help you to change a particular text:Let's assume that the following content "Adam went to the store" is in a text file named textFile.txttextChar = fileread("textFile.txt");indices = regexp(textChar,' '); % get indices of the ' ' in textChartextChar(indices) = '_'If you want to do the same using for loop, then iterate through textChar (from above) to find ' ' and replace it with '_' . MATLAB: Search an entire text file for a word content = fileread( 'MyTextFile.txt' ) ;and then you can STRFIND or REGEXP or anything else on content, which is a char array. Related QuestionTo read a text file using matlabHow to remove certain lines of text in a text fileI want to delete all the headerlines and delimiters from the data in the below attached text fileRead text file and store in .mat fileExporting Lines from One Text File to Another
Best Answer