sed regexp to match last occurance in stream - Unix
This is a discussion on sed regexp to match last occurance in stream - Unix ; Hi
This is propably too simple for most but I can't figure it out.
I have a stream coming out of
x1=`grep -o "X.\.[0-9]*" data.af2 | {sed statment}`
X6.547
X6.57
X6.618
data.af2 =
X6.547Z-0.338
X6.57Z-0.328
X6.618Y1.411
there are several files ...
-
sed regexp to match last occurance in stream
Hi
This is propably too simple for most but I can't figure it out.
I have a stream coming out of
x1=`grep -o "X.\.[0-9]*" data.af2 | {sed statment}`
X6.547
X6.57
X6.618 < match this one
data.af2 =
X6.547Z-0.338
X6.57Z-0.328
X6.618Y1.411
there are several files like data.af2 and I need to extract the last
occurance of X.... Y.... Z....
from each file and store them in a Var. to construct a line contaning
G1X....Y.... Z....F20. this will reposition the machine tool to the
last location of the previous file.
the above is a section of a ksh script that breaks a large file in to
managable bits.
Thanks for you time
Jim
-
Re: sed regexp to match last occurance in stream
On 2007-05-01, hoodcanaljim wrote:
> Hi
>
> This is propably too simple for most but I can't figure it out.
> I have a stream coming out of
>
> x1=`grep -o "X.\.[0-9]*" data.af2 | {sed statment}`
> X6.547
> X6.57
> X6.618 < match this one
This kind of thing doesn't lend itself naturally to regexps. Have
you considered "tail -n 1" to simply discard everything but the
last line?
--
Andrew Smallshaw
andrews@sdf.lonestar.org
-
Re: sed regexp to match last occurance in stream
On May 1, 1:59 pm, hoodcanaljim wrote:
> Hi
>
> This is propably too simple for most but I can't figure it out.
> I have a stream coming out of
>
> x1=`grep -o "X.\.[0-9]*" data.af2 | {sed statment}`
> X6.547
> X6.57
> X6.618 < match this one
>
> data.af2 =
> X6.547Z-0.338
> X6.57Z-0.328
> X6.618Y1.411
>
> there are several files like data.af2 and I need to extract the last
> occurance of X.... Y.... Z....
> from each file and store them in a Var. to construct a line contaning
> G1X....Y.... Z....F20. this will reposition the machine tool to the
> last location of the previous file.
>
> the above is a section of a ksh script that breaks a large file in to
> managable bits.
>
> Thanks for you time
> Jim
No!
thats what I was hoping for something I had overlooked and far simpler
than I was trying to use.
But!
seems like I need help with my "grep " also. grep is doing fine as
long as the numbers don't have a "minus" sign after the value.
Z-..... is not being found
grep -o "X.\.[0-9]* works fine but won't find a negative X value
grep -o "Z-.\.[0-9]* works fine but won't fine a positive Z value
I arrived at "Z.\.[0-9]" by trial and error and still don't know why
it dose'nt work with out the "." behind the X
Thanks
Jim
-
Re: sed regexp to match last occurance in stream
On May 1, 3:26 pm, hoodcanaljim wrote:
> On May 1, 1:59 pm, hoodcanaljim wrote:
>
>
>
> > Hi
>
> > This is propably too simple for most but I can't figure it out.
> > I have a stream coming out of
>
> > x1=`grep -o "X.\.[0-9]*" data.af2 | {sed statment}`
> > X6.547
> > X6.57
> > X6.618 < match this one
>
> > data.af2 =
> > X6.547Z-0.338
> > X6.57Z-0.328
> > X6.618Y1.411
>
> > there are several files like data.af2 and I need to extract the last
> > occurance of X.... Y.... Z....
> > from each file and store them in a Var. to construct a line contaning
> > G1X....Y.... Z....F20. this will reposition the machine tool to the
> > last location of the previous file.
>
> > the above is a section of a ksh script that breaks a large file in to
> > managable bits.
>
> > Thanks for you time
> > Jim
>
> No!
> thats what I was hoping for something I had overlooked and far simpler
> than I was trying to use.
>
> But!
> seems like I need help with my "grep " also. grep is doing fine as
> long as the numbers don't have a "minus" sign after the value.
> Z-..... is not being found
> grep -o "X.\.[0-9]* works fine but won't find a negative X value
> grep -o "Z-.\.[0-9]* works fine but won't fine a positive Z value
>
> I arrived at "Z.\.[0-9]" by trial and error and still don't know why
> it dose'nt work with out the "." behind the X
>
> Thanks
> Jim
What wondererfull things come in small packages. tac - will copy a
file and reverse the order of the lines without altering the position
as sort will do.
A regex that works with or without a "minus" number
x1=`grep -o "X.[0-9]*\.[0-9]*" data.af"$i" | tail -n 1`
Thanks for everyones help
Jim