bug-textutils
[Top][All Lists]
Advanced

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

Re: cut 2.0a


From: Bob Proulx
Subject: Re: cut 2.0a
Date: Fri, 10 May 2002 10:42:14 -0600

> So cut is not a solution to print specific fields of input lines unless the 
> delimiter is exactly one character. 

Correct.

> How often do the GNU utilities actually use tabs for that purpose? Obviously 
> 'wc' doesn't.

Correct again.

What you are forgetting is that UNIX is an operating system that has
been around for a long time.  Many of the commands were written by
different people with differing ideas about how things should work.
The cut program in particular was designed to cut tabular report data
apart.  At the time tabular report data was normally separated by
tabs with no leading whitespace.

The cut program could be changed to do things differently.  But then
it would not be cut, it would be sed, awk, perl, ruby, etc.  That
change would break a lot of working programs today and would upset
many people that expect cut to work like it has been working for
literally 30 years.  Obviously that would be bad and so cut will
always behave like it does.

What you are wanting is a completely different program.  In order not
to break existing programs that already use cut the way it is written
new behavior must be a different program name.  Many such programs
exist and are thriving with many new features.  The wonderful thing
about free software is that you are also free to create your own
program, say xcut, which is more powerful and has the features that
you need.

Try this.  This is probably the simplest method of cutting fields.

  wc -l ~/.alias | awk '{print$1}'

And here is another.  Always cuts the last field.  NF is the number of
fields.

  wc ~/.alias | awk '{print$NF}'

And of course with perl and ruby and other such programs there are
endless ways of manipulating the data.

Bob

> I run 'wc' on a file, .alias, containing 14 lines. It prints:
>      14 /home/hacksaw/.alias
> 
> 'wc -l ~/.alias | cut -f1' produces the same thing. This is non-intuitive.
> 
> 'wc -l ~/.alias | cut -f1 -d" "' produces a blank line
> 
> 'wc -l ~/.alias | cut -f1 -d"     "' produces
> cut: the delimiter must be a single character
> 
> So cut is not a solution to print specific fields of input lines unless the 
> delimiter is exactly one character. 
> 
> How often do the GNU utilities actually use tabs for that purpose? Obviously 
> 'wc' doesn't.



reply via email to

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