[Top][All Lists]

[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: Dii
Subject: Re: Help me to extract the part of Text file to another format
Date: Sat, 12 Mar 2016 10:05:34 -0800 (PST)

mjayiitk2013 wrote
> Hi all,
> I have a text file 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
> I want to extract the second column between "offset 0" to "X-Ray" in a row
> then another piece in another row
> I have similar files a lot so i want to change all in this manner
> Please guide me to make a script for it

This page is you friend now, it provides info on relevant functions:
I'll provide some example, but someone who actually knows your goals might
find a room for a few improvements to those. Also, there's also page for
complete file readings which theoretically should be faster, but I'm not
experienced with those.


    s=fgetl(f);%this provides you first line
    while s~=-1 %until the end of file
        if strmatch('offset',s);
        %here you do your data processing for ex:
            while ~strmatch("X-ray",s)
                 [~,~,~,~,row{i}]=regexp(s, '\d (\d+)' , 'once' );%quotes in
regexp are single
                 i=i+1; s=fgetl(f);
                 %by the end of this cycle you'll have cell array of cell(1)
arrays of strings representing your   
        s=fgetl(f);%this provides you next line line

View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

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