help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help me to extract the part of Text file to another format


From: Nicholas Jankowski
Subject: Re: Help me to extract the part of Text file to another format
Date: Sat, 12 Mar 2016 15:59:29 -0500


On Mar 12, 2016 10:03 AM, "mjayiitk2013" <address@hidden> wrote:
>
> Hi all,
>
> I have a text file  40%ROL~1.TXT
> <http://octave.1599824.n4.nabble.com/file/n4675435/40%25ROL%7E1.TXT>   who
> has pattern of this kind
>
> info info info
> info X X X
> Info
> offset 0
> 1 344
> 2 43432
> 4 34234
> 3 4323
> X-ray
> Info
> Info
> offset 0
> 1 3441
> 2 43431
> 4 34231
> 3 4321
> X-ray
> ....
> ....
> I want to extract the second column between "offset 0" to "X-Ray" in a row
> then another piece in another row
> like
> 344 43432 34234 4323
> 3441 43431 34231 4321
>
>
> I have similar files a lot so i want to change all in this manner
> Please guide me to make a script for it
>
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Help-me-to-extract-the-part-of-Text-file-to-another-format-tp4675435.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave

Okay, I used to do this kind of stuff all the time with octave. I have found that the easiest way is to use the fgetl command. "help fgetl" will get you the syntax. I'm not at my computer right now to give you actual code snippets.

Fgetl will read in one line. You can put it inside a while loop that doesn't end until it hits the end of the file (the read data will give EOF).

Inside of this while loop , you can use the strcmp command to check whether or not you hit the offset 0 line. Then if it matches, read the next series of data until it gives the X-ray line, processing that data as you go along. Continue until the end of the file , picking up each section as you go.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]