Thread Subject:
scanning text file and writing from .txt file

Subject: scanning text file and writing from .txt file

From: Kunal

Date: 3 Aug, 2012 23:21:42

Message: 1 of 2

Hi,
I have this data in a txt file:
time = 0.0000E+00
 mat.#= 1012 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00
 x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00
 x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00
 mat.#= 1013 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00
 x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00
 x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00
 mat.#= 1014 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00
 x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00
 x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00..............
I want to write a code which reads this text line by line and prints the 'mat.#' whose intern=0.0000E+00

Subject: scanning text file and writing from .txt file

From: dpb

Date: 5 Aug, 2012 14:54:25

Message: 2 of 2

On 8/3/2012 6:21 PM, Kunal wrote:
> Hi,
> I have this data in a txt file:
> time = 0.0000E+00
> mat.#= 1012 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00
> x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00
> x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00
> mat.#= 1013 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00
> x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00
> x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00
> mat.#= 1014 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00
> x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00
> x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00..............
> I want to write a code which reads this text line by line and prints the
> 'mat.#' whose intern=0.0000E+00

I don't see anything where there's a string 'intern'. You mean 'inten'
I suppose???

If the above is the extent of the need, probably simplest to just parse
on the fly...

fid=fopen('yourfile','rt');
while ~feof(fid)
   l=fgetl(fid);
   if strmatch('mat.#',l)
     if sscanf(l(20:30),'%f')==0
       disp(l(1:12))
     end
   end
fid=fclose(fid);

Salt to suit, obviously...

--

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
text file Kunal 3 Aug, 2012 19:24:30
scanning Kunal 3 Aug, 2012 19:24:30
writing Kunal 3 Aug, 2012 19:24:30
rssFeed for this Thread

Contact us