Append and add lines in text/dat file
Show older comments
I have a .dat file from CFD postprocessing with variable data regularly listed. I am currently reading through the files fine, but I want to add variable data. I attached an image of the data structure below (this is only an excerpt; the full file is hundreds of thousands of lines, which is the reason that I can't do it manually).
Right now, I am just reading the data. But I will need to add a few things, among them:
- Two new lines after line 14, but before line 15.
- Two numbers apppended to the end of each variable line; for example, adding " 0.000000000E+00 0.000000000E+00" to the end of line 21 (the numbers themselves will be calculated using a routine I've already completed)
- Ignoring lines with two numbers on them.
I have the logic worked out, but I am having trouble a) figuring out how to overwrite the current line/append data to a line itself, and b) formatting numbers the same way: scientific notation with 9 digits (easy), captial E (easy), and a plus/minus with two numbers for the exponent.
I have been using fgetl to read through the data, and the easiest way to do this would be (if appending itself is impossible) to rewrite the line in its entirety by simply setting the current line to a different string. There have been a few posts that I've seen that say this is impossible, but I find this hard to believe. Writing data algorithmically like this seems too easy not to be possible.
Thanks for any help.

Accepted Answer
More Answers (0)
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!