[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: |
Mike Miller |
Subject: |
Re: Help me to extract the part of Text file to another format |
Date: |
Sun, 13 Mar 2016 14:33:38 -0700 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
On Sat, Mar 12, 2016 at 04:22:04 -0800, mjayiitk2013 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
This seems like a "simplest tool for the job" case where Octave is not
the answer. You could do something like the other responses you've
gotten, or you could use a simple sed command:
sed -n '/offset 0/d; /^[0-9]\+ [0-9]\+/H; /X-ray/{x;s/[^0-9]*[0-9]\+
\([0-9]\+\)\(\n\|$\)/\1 /g;s/ *$//;p}'
--
mike