Jacob, Raymond A Jr
12/3/2006 7:33:00 PM
To: Gregory Seidman ] and David Vallner
Thank you,
Raymond
-----Original Message-----
From: Gregory Seidman [mailto:gsslist+ruby@anthropohedron.net]
Sent: Sunday, December 03, 2006 13:50
To: ruby-talk ML
Subject: Re: Can one use line addresses...to select a portion of file
On Mon, Dec 04, 2006 at 03:19:25AM +0900, Jacob, Raymond A Jr wrote:
} I would like to select a portion of a file to process like I did with
} sed.
}
} i.e. a file called Menu with the following contents:
} __McDonalds__
}
} ...
} ...
} ...(stuff deleted)
}
} __Happy_Meal__
}
} With sed I would do something like
}
} sed -n "/__McDonalds__/,/__Happy_Meal__/p" Menu } } I can not find
anything comparable in Ruby. I may be using the wrong } words when I
searched google for ruby line address.
} Any help will be appreciated.
Well, sometimes sed (or awk, which does the same thing even more simply:
awk '/__McDonalds__/,/__Happy_Meal__/') is the right tool. If you are
selected this subset of lines for further processing in ruby, however
try
this:
inrange = false
lines = open(file).read.split("\n").select { |line|
inrange &&= not /__Happy_Meal__/ === line
inrange ||= /__McDonalds__/ === line
}
} Thank you,
} Raymond
--Greg