[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: Fri, 22 Dec 2006 15:24:59 -0700
User-agent: Mutt/1.5.9i

Juhana Sadeharju wrote:
> Hello. The "cut" (version 2.0.21)

Wow.  That is very old.  The current release is 6.7.  Please upgrade!
Please see this announcement for information about newer versions.


> might have a bug with
>   cut -f 6- -d ' '
> as it counts each ' ' as a field.

Yes.  That is the correct and required behavior.  But cut is actually
very poor at cutting out fields.  I only very rarely use it for such
things.  I recommend using awk for that purpose.

> That makes impossible to cut columns out of "tar tvf" listings.

The sixth field of a tar tvf listing is simply the filename.  If you
wish to remove the other information then simply do not print it with
tar.  That is, instad of:

  tar tvf foo.tar | sed 's/  */\t/g' | cut -f6

Use this instead:

  tar tf foo.tar

Without the 'v' option only the filenames will be printed.

> Example: the input file is
> a b c
> a  b c
> a   b c
> cat test | cut -d ' ' -f 2-  gives
> b c
>  b c
>   b c
> instead of
> b c
> b c
> b c

That is the required behavior for cut.  After 30 years it would be
impossible to change it now.

If you want to group all whitespace together when calling out fields I
recommend using awk which is much better at printing fields such as

  echo " a  b   c" | awk '{print$2}'
  echo " a  b   c" | awk '{print$NF}'


reply via email to

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