[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cut bug?

From: Bob Proulx
Subject: Re: cut bug?
Date: Wed, 27 Dec 2006 16:03:53 -0700
User-agent: Mutt/1.5.9i

Juhana Sadeharju wrote:
> Hello again. I don't use "tar" directly because I generate "tar tvf"
> listings for later use. The more info in the listings, the better.

That seems reasonable.  Thanks for clarifying that.

> How awk handles " " chars in the filenames?

My example would split on all whitespace and would therefore only
print the final part of the filename.

But as I understand it this will be a limitation of "tar tvf" listing
output since there is no escape mechanism there for filenames
containing spaces or newlines or other such problematic characters.  I
don't think there is a way to handle those perfectly unless the
filenames are zero terminated strings.

You may have better luck at just cutting off the leading 51 columns
with cut.  But I expect that to be very fragile and non-portable.

  tar tvf foo.tar | cut -c52-

I would be inclined to try something more like cutting off the first
five fields of the line.

  tar tvf foo.tar \
  | awk '{for(i=0;i<5;++i){sub(/[^[:space:]]*[[:space:]]*/,"");}print$0}'

  tar tvf foo.tar \
  | sed 's/\([^[:space:]]*[[:space:]]*\)\{5\}//'

But that still won't handle arbitrary whitespace such as newlines in
the filenames.

> I have had great problems with them. I wish I could list and access
> files by some file IDs in find, tar, ls etc. Has anyone written such
> versions?

I am not aware of any such features.

> I have written "tardu" which generates du listing directly from
> the "tar tvf" output. Interested? The code needs a rewrite to the
> GNU coding standards.

Probably not for coreutils proper.  But if you released this code
under a free license and posted it for others then I am sure there are
those that would find it useful.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]