how to update a specific line in a text file

Hi folks,
I am going to read a formatted text file and update ONLY a line of that which can be in middle of text file. e.g. if contents of my text file are as the following:
test1 a1 a2 a3
test2 b1 b2 b3
test3 c1 c2 c3
I just want to update the the second line of this text file with new values like:
test2 f1 f2 f3
without changing other two lines so that I end up with
test1 a1 a2 a3
test2 f1 f2 f3
test3 c1 c2 c3
Is there any way to do so?
thanks in advance, --V

 채택된 답변

Yash
Yash 2012년 6월 30일

1 개 추천

read the text file and them make changes to the array and then rewrite it

댓글 수: 1

Vahid
Vahid 2012년 6월 30일
편집: Vahid 2012년 6월 30일
thanks so much! I was thinking to apply exactly same way to resolve my problem:
  • first, read the data from the text file and save the data in an array
  • second, changing the desired element in the array
  • third, writing the updated array to the text file
It should perfectly work ;D

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

질문:

2012년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by