[Top][All Lists]

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

Re: cut bug?

From: Andrew D Jewell
Subject: Re: cut bug?
Date: Thu Nov 7 16:14:30 2002

Alternately, you can used the enhanced cut in




cut, as well as all the other field based tools, supports --dw to set the delimiter to "whitespace" and does what you want.


At 11:16 AM -0700 11/7/02, Bob Proulx wrote:
Bill Cecchin <address@hidden> [2002-11-01 10:27:37 -0800]:
 I am not sure if this is a bug or just lack of knowledge on my part.  In
 Unix I could always use 'cut' to pull the needed fields out of our text
 files.  In GNU Utilities I can't find any combination of parameters that
 will allow using 'cut' on a file delimited by spaces. Is it possible to
 cut a file using a SPACE as a delimiter between fields?

The cut program is a very old program and on all unixlike systems of
which I am aware the default field delimiter is a TAB.  The original
use of the program was for tabular data in data files which had fields
separated by TABs.

You can set the field delimiter to be anything you want using the -d
option.  That is a standard option and should work on all unixlike

  cut -d ' ' -f 2

But the behavior is such that this is probably not what you want to
do.  The cut program will treat a leading space as an empty field by
definition.  The field numbers are different if there are leading
spaces or not.  This is not a bug but part of the definition and use
of the cut command.  Therefore awk is really a better choice for most
free form data that you just want to pull out fields.

Using cut you can see that it is sensitive to field separators.
Although the use it is put to will define this.  It all depends on
what you want.

  echo one two three | cut -d ' ' -f 2

  echo "one two three" | cut -d ' ' -f 2

  echo " one two three" | cut -d ' ' -f 2

Using awk most people find this result more intuitive.

  echo one two three | awk '{print $2}'

  echo "one two three" | awk '{print $2}'

  echo " one two three" | awk '{print $2}'


Bug-textutils mailing list

reply via email to

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