[lug] Something seemingly simple
David L. Anselmi
anselmi at anselmi.us
Tue Dec 19 16:08:12 MST 2006
Daniel Webb wrote:
> On Tue, Dec 19, 2006 at 07:30:57AM -0700, Hugh Brown wrote:
>>So the line is NULL terminated and each field can have anything in it
> Yes, I'm trying to store owner, group, permissions, etc, separated by spaces,
> then a Unix filename, which means null termination. So I can know that there
> will be X variable, space-delimited fields, followed by the filename which can
> have any character except null. The question is how to extract only the
> filename from such a line. I still haven't figured out a way to do it with
> the standard unix tools.
If you want standard (shell) tools you ought to get different data.
Otherwise use different tools (like C, though Perl, Python, etc should
work). The shell has too many conventions where space and newline are
significant and expanded variables aren't the same as references.
In Perl you're looking for split(). If you're careful about your data
that could work but since your last field can contain spaces Perl will
consider it to be multiple fields. Since it's the last you could do it,
but it's messy.
More information about the LUG