[lug] Something seemingly simple

Daniel Webb lists at danielwebb.us
Tue Dec 19 00:05:32 MST 2006


I want something to take a space-delimited string and return only the last
field.  The caveat: the "last field" can have any character except NULL.  How
can I extract this field from a bash variable or from a file that contains
such an entry?

Most obvious ways (bash's 'read' internal, cut, sed) all normally end
searching for a pattern when they find a newline.  I'm thinking something like
perl's s///s construction, but I don't want a Perl dependency.  Is it possible
with the standard GNU toolkit?




More information about the LUG mailing list