필터 지우기
필터 지우기

How to edit specific lines of a large text file?

조회 수: 4 (최근 30일)
Ehsan Fatourehchi
Ehsan Fatourehchi 2017년 3월 24일
편집: Ehsan Fatourehchi 2017년 4월 7일
Hi all, I have a large text file, about 7000 lines, and I need to read and edit specific lines, 300 lines, in the middle of the file. How can I skip unneeded lines?
  댓글 수: 2
ES
ES 2017년 3월 24일
Some more details?
Do you know which specific line number, line content you should start editing?
Ehsan Fatourehchi
Ehsan Fatourehchi 2017년 3월 24일
Yes, I need to edit lines from 6600 to 6900. The start word of these lines is TEMP.

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

채택된 답변

dbmn
dbmn 2017년 3월 24일
If you already know the line number that you need to edit, I suggest to use one of the following solutions on matlabcentral https://de.mathworks.com/matlabcentral/answers/62986-how-to-change-a-specific-line-in-a-text-file
If you dont know your line number yet, but know some test-marker (f.ex. TEMP....TEMP) you can read on the Matlab functions
regexprep
regexp
or check out this answer
hope this helps.
  댓글 수: 1
Ehsan Fatourehchi
Ehsan Fatourehchi 2017년 4월 7일
편집: Ehsan Fatourehchi 2017년 4월 7일
Thank you and Walter Roberson. I have finally made it by doing the following procedure: Identity the byte offsets of the values which needs to be changed. Then, each time, fopen asking for 'r+' access. fseek to the position, fwrite the new content, fclose. Since I have 900 different values to change, I created a matrix for byte offsets of the values beforehand.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by