delete element from txt file

hi, is there a way to delete element from txt file . I have files ,I want delete the first two elements in each file.
the structure of my file(1) as:
1:
text.....
file(2)
2:
text.....
etc.
I want to delete 1:, 2:, 3: etc...
thanks

Antworten (1)

Walter Roberson
Walter Roberson am 6 Nov. 2011

0 Stimmen

It is greatly recommended that if you need to delete something from a text file, that you copy the parts that you want to keep to a new file, possibly renaming files afterwards. Deleting text from an existing file is messy.

5 Kommentare

huda nawaf
huda nawaf am 6 Nov. 2011
hi,
I read stream of files using dir, then use textscan.
the problem there is unwanted values in each of files.
for ex.
unwanted values are 1:,2:,etc from aove files.
I want to delete it , then use textscan.
can textscan avoid these values when scan file?
thanks
txt
In each file, there is
Walter Roberson
Walter Roberson am 6 Nov. 2011
The 1:, 2: and so on: if there is only one such line per file and it is the first line of the file, then specify 'HeaderLines', 1 when you textscan.
If there are multiple instances per file, then is there always the same number of lines between instances?
huda nawaf
huda nawaf am 7 Nov. 2011
yes, each file has one such line, and the first line.
But, I did help HeaderLines, there is no.
how use it please. thanks
huda nawaf
huda nawaf am 7 Nov. 2011
4:
1666394,3,2005-04-19
1759415,4,2005-04-22
1959936,5,2005-11-21
998862,4,2004-11-13
2625420,2,2004-12-06.
I don't want 4:
I used
c = textscan(f,'%f %f %s','headerLines',1);
I got:
c =
[1666394] [] {}
how I can textscan to return c{1} as:
1666394
1759415
1959936
998862
2625420
thanks
Walter Roberson
Walter Roberson am 7 Nov. 2011
c = textscan(f,'%f %f %s','Delimiter',',','headerLines',1);

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 6 Nov. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by