how can i find specific lines in a text file, duplicate them and edit them?
1 view (last 30 days)
Show older comments
Hi,
i am lookin for a way in which I can find sepcific lines in a text file and duplicate them. The content of my text files are as follows:
Original text line:
0.06 , MAT13, 0
0.004, MAT14, 0
0.001, MAT9, 0
0.004, MAT14, 0
0.04, MAT13, 0
I would like to duplicate the text line with the content 'MAT13' as shown below:
Duplicate:
0.06 , MAT13, 0
0.06 , MAT13, 0
0.004, MAT14, 0
0.001, MAT9, 0
0.004, MAT14, 0
0.04, MAT13, 0
0.04, MAT13, 0
And later replace the duplicated lines with 'MAT13' to the following:
Edit:
0.06 , MAT13, +45
0.06 , MAT13, -45
0.004, MAT14, 0
0.001, MAT9, 0
0.004, MAT14, 0
0.04, MAT13, -45
0.04, MAT13, +45
And in the final form reduce the first integer in the line with the content 'MAT13' by half, as shown below:
Final Target:
0.03 , MAT13, +45
0.03 , MAT13, -45
0.004, MAT14, 0
0.001, MAT9, 0
0.004, MAT14, 0
0.02, MAT13, -45
0.02, MAT13, +45
The contents of the text file shown above are just an example and in reality the term 'MAT13' would be recuring more than 20,000 times in the original text file. Could someone help me with this? Any pointers might be of great help.
Thanks
0 Comments
Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!