On Saturday 11 January 2003 08:56 pm, Jim C wrote:
I have a list of positive integers of which I only want the first one.
They are of arbitrary size. How can I cut the rest of them off?
I've been trying to write a regular expression for this using sed or awk.
you don't specify the format of the integers. are they space separated
and all on one line? or are they line separated (each integer on
its own line)?
are there blank spaces (if the first) or blank lines (if the second) before
the first integer?
Blank spaces are between the numbers.
or are they in some other format? you say they're arbitrary size, so does
that mean they aren't in some fixed column format?\
No fixed columns. What they are is a line of userids with spaces
between them.
if they're one integer to a line, then head (for the first), tail (for the
last), or some combination of head and tail (for anything in between)
will get you the integer you want.
There is only one line... but that is a good idea. I might be able to
arrange for them to be in one column. Then I could use head. :-) I'll
try that and let you know.
if they're delimited by something (spaces, commas, colons, whatever),
then cut -f <fldnumber> -d "<delimiter>" might help. otherwise,
well, sed, awk, or some custom program in your favorite language.
sed and awk are driving me nuts. ;-)
if there are blank lines or blank fields before the first number, then
some sort of bash while loop would be needed to ignore the
blank lines or blank fields, print the first non-blank field, and then
exit the loop.
Want to buy your Pack or Services from MandrakeSoft?
Go to http://www.mandrakestore.com