Changing a specific column in txt file

2 vues (au cours des 30 derniers jours)
Varghese
Varghese le 15 Jan 2014
Dear group, I am looking to change the value in a specific column in a txt file. In the attached txt file, I want to change the 1's in the third column to the previous value (same column, previous row) and delete the previous row. Any help would be much appreciated.

Réponses (1)

Walter Roberson
Walter Roberson le 15 Jan 2014
There is no mechanism to change text files "in place" -- not unless the replacement is exactly the same size as the original.
You need to read the file and write each line in turn to a new file, except writing the new versions of the lines instead of writing the old versions. Then once past the part to change, keep reading from the old and copying to the new. Close the files. If needed, rename the new file to have the name of the old file.

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by