FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 11-21-2007, 01:27 PM
Tim Waugh
 
Default why does "cut" print fields in original order?

For what it's worth, cut(1) is just following the spec.

"The elements in list can be repeated, can overlap, and can be specified
in any order, but the bytes, characters, or fields selected shall be
written in the order of the input data."

and later, in "Rationale":

"""
The list option-arguments are historically used to select the portions
of the line to be written, but do not affect the order of the data. For
example:

echo abcdefghi | cut -c6,2,4-7,1


yields "abdefg".

A proposal to enhance cut with the following option:


-o
Preserve the selected field order. When this option is
specified, each byte, character, or field (or ranges of such)
shall be written in the order specified by the list
option-argument, even if this requires multiple outputs of the
same bytes, characters, or fields.

was rejected because this type of enhancement is outside the scope of
the IEEE P1003.2b draft standard.
"""

So the answer to the original poster's question is: because the spec
requires the order to be ignored.

Tim.
*/

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 01:43 PM
Ed Greshko
 
Default why does "cut" print fields in original order?

Dave Ihnat wrote:

> Now, as to why it does what it does? I don't know for sure, since
> I didn't go find whoever wrote the original and ask. But I can
> guess--"do one thing, and do it well." Cut is supposed to get fields
> from a line-delimited data stream. Period. Rearrangement is an added
> function--one that might be useful, certainly; but that can be done via
> other shell tools.

Exactly what I thought. It was designed to do a simple function and no more
, no less.

It does exactly what it was intended to do.

Why some folks would want it (or expect it) to do more is beyond me. :-)

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 02:35 PM
Dave Ihnat
 
Default why does "cut" print fields in original order?

On Wed, Nov 21, 2007 at 10:43:16PM +0800, Ed Greshko wrote:
> Why some folks would want it (or expect it) to do more is beyond me. :-)

Oh, I understand it; "you've already GOT the fields, why not let me
rearrange them?". Simple--if you don't know the philosophy behind the
way Unix was evolving. (And yes, I know you know that--I saw the smiley.
Just an opportunity to reminisce--or pontificate, take your pick.)

People today take the shell, and its ability to allow the normal user
to make complex commands (scripts)from a grab-bag of special-purpose
commands, for granted. It was actually a radical innovation--the common
model for a CLI back then was that it a privileged part of the OS,
and you used what you were given, by Ghu.

In the explosion of tools and utilities that this new model spawned,
there were literally hundreds of commands that totally confused the new
Unix user. "Why in the name of all that's holy would you ever need a
command called 'tr'?" (substitute your favorite confusing little program.)
And this was a logical question--IF you didn't look at all these utilities
as pieces to use in building a script.

Actually, I've always regretted that Job's NeXT never survived. NextStep
had a pretty cool concept that did for GUI-based commands what the shell
did for the CLI--a toolkit of graphical objects that you piped together.
Unfortunately, the NeXT didn't survive, and although NextStep was eventually
made available separately for the Intel platform, it's clearly never really
become generally used, and its GUI toolkit model hasn't been picked up.

Cheers,
--
Dave Ihnat
President, DMINET Consulting, Inc.
dihnat@dminet.com

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 02:57 PM
"Robert P. J. Day"
 
Default why does "cut" print fields in original order?

On Wed, 21 Nov 2007, Dave Ihnat wrote:

> Actually, I originally wrote cut & paste, but after the initial release,
> left it on its own. Thankfully, David MacKenzie and Jim Meyering (neither
> of whom I've ever met or communicated with) picked up the ball and kept
> working on the programs. (And whatever prompted me to spend the time to
> recreate these programs? I was working on a Unix clone called 'Venix',
> and was annoyed that it didn't have these commands.)
>
> I wrote the programs to be as close to identical to the original Unix
> System 5 man page as I could, and "reverse-engineered" it from the man
> page description of behavior and options, deliberately not ever referring
> to or accessing the original source, since it was copyrighted material
> of AT&T. At the time I was reverse engineering it, I asked numerous
> questions on Usenet as to whether I should fix obvious bugs or deviations
> in behavior, or extend the command; the overwhelming response was "make
> it behave like the 'real' command".
>
> Now, as to why it does what it does? I don't know for sure, since
> I didn't go find whoever wrote the original and ask. But I can
> guess--"do one thing, and do it well." Cut is supposed to get fields
> from a line-delimited data stream. Period. Rearrangement is an added
> function--one that might be useful, certainly; but that can be done via
> other shell tools.

yes, i now appreciate that cut's behaviour is the very efficient
technique of treating the data as a one-way stream, so i'm good with
that. so lay off already. ya hear me?? LAY OFF!!!

double shot espresso: accept no substitutes.

rday
--
================================================== ======================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
================================================== ======================

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 06:31 PM
Tony Nelson
 
Default why does "cut" print fields in original order?

At 10:57 AM -0500 11/21/07, Robert P. J. Day wrote:
>On Wed, 21 Nov 2007, Dave Ihnat wrote:
>
>> Actually, I originally wrote cut & paste, but after the initial release,
>> left it on its own. Thankfully, David MacKenzie and Jim Meyering (neither
>> of whom I've ever met or communicated with) picked up the ball and kept
>> working on the programs. (And whatever prompted me to spend the time to
>> recreate these programs? I was working on a Unix clone called 'Venix',
>> and was annoyed that it didn't have these commands.)
>>
>> I wrote the programs to be as close to identical to the original Unix
>> System 5 man page as I could, and "reverse-engineered" it from the man
>> page description of behavior and options, deliberately not ever referring
>> to or accessing the original source, since it was copyrighted material
>> of AT&T. At the time I was reverse engineering it, I asked numerous
>> questions on Usenet as to whether I should fix obvious bugs or deviations
>> in behavior, or extend the command; the overwhelming response was "make
>> it behave like the 'real' command".
>>
>> Now, as to why it does what it does? I don't know for sure, since
>> I didn't go find whoever wrote the original and ask. But I can
>> guess--"do one thing, and do it well." Cut is supposed to get fields
>> from a line-delimited data stream. Period. Rearrangement is an added
>> function--one that might be useful, certainly; but that can be done via
>> other shell tools.
>
>yes, i now appreciate that cut's behaviour is the very efficient
>technique of treating the data as a one-way stream, so i'm good with
>that. so lay off already. ya hear me?? LAY OFF!!!
...

This all rather begs the question of what tool to use after cut in order to
reorder the fields? Don't pretend the answer is sed or awk, or their ilk.
--
__________________________________________________ __________________
TonyN.:' <mailto:tonynelson@georgeanelson.com>
' <http://www.georgeanelson.com/>

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 07:28 PM
"Mikkel L. Ellertson"
 
Default why does "cut" print fields in original order?

Tony Nelson wrote:
>
> This all rather begs the question of what tool to use after cut in order to
> reorder the fields? Don't pretend the answer is sed or awk, or their ilk.
How about something like "echo $2 $1"?

Mikkel
--

Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 07:29 PM
Todd Zullinger
 
Default why does "cut" print fields in original order?

Tony Nelson wrote:
> This all rather begs the question of what tool to use after cut in
> order to reorder the fields?

Why use anything after cut when you can more easily just replace cut
for this task?

> Don't pretend the answer is sed or awk, or their ilk.

How would I be pretending about this output?

awk -F : '{print $7, $1}' /etc/passwd
/bin/bash root
/sbin/nologin bin
/sbin/nologin daemon
...

--
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
The triumph of persuasion over force is the sign of a civilized
society.
-- Mark Skousen

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 07:55 PM
Les Mikesell
 
Default why does "cut" print fields in original order?

Tony Nelson wrote:


yes, i now appreciate that cut's behaviour is the very efficient
technique of treating the data as a one-way stream, so i'm good with
that. so lay off already. ya hear me?? LAY OFF!!!

...

This all rather begs the question of what tool to use after cut in order to
reorder the fields? Don't pretend the answer is sed or awk, or their ilk.


If you'd rather pretend that more suitable tools don't exist, cut each
field you want into its own file, then use paste to glue them back in
the order you want. Be careful to use suitable tmp names so concurrent
runs don't break.


--
Les Mikesell
lesmikesell@gmail.com

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 08:26 PM
Tony Nelson
 
Default why does "cut" print fields in original order?

At 2:28 PM -0600 11/21/07, Mikkel L. Ellertson wrote:
>Tony Nelson wrote:
>>
>> This all rather begs the question of what tool to use after cut in order to
>> reorder the fields? Don't pretend the answer is sed or awk, or their ilk.
>How about something like "echo $2 $1"?

That will work if cut's output doesn't need to be quoted, that is, if it
doesn't contain arbitrary characters.
--
__________________________________________________ __________________
TonyN.:' <mailto:tonynelson@georgeanelson.com>
' <http://www.georgeanelson.com/>

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 11-21-2007, 08:59 PM
Cameron Simpson
 
Default why does "cut" print fields in original order?

On 21Nov2007 02:12, Robert P. J. Day <rpjday@crashcourse.ca> wrote:
| On Wed, 21 Nov 2007, Frank Cox wrote:
| > On Wed, 21 Nov 2007 01:44:26 -0500 (EST)
| > "Robert P. J. Day" <rpjday@crashcourse.ca> wrote:
| > > i understand that that's not indicated on the man page. on the
| > > other hand, is there any reason that it *wasn't* done that way?

Because cut is a data pruning tool, not a reporting tool.

| > > it would seem that that would be an obvious enhancement and,
| > > certainly, that would be more intuitive behaviour, no?

It would never have occured to me to cut fields out of order.

You've got awk et al for reporting.

| > It would be fairly trivial to "roll your own" if you require that
| > functionality.
|
| yes, i realize that -- i'm just baffled why that wasn't the obvious
| behaviour in the first place. i mean, i'm trying to imagine the
| brainstorming session:
|
| A: "and if the user asks for fields 1 and 2, we'll print 1 and 2."
| B: "yup, i'm all over that."
| A: "and if he asks for 2 and 1 ... i know, we'll still print 1, then
| 2. hahahaha! oh, man, sometimes i crack me up!"

Or... "Hmm, I only want a few fields from the input,so I'll write a tool
to crop the input on demand."

Once you realise that cut _cuts_ stuff it's all obvious. It doesn't
start with a blank output and fill stuff in, it starts with a filled in
line and cuts stuff out.

| i'm just curious what kind of thinking went into doing something so
| non-intuitive.

I'm not. You're reading more into the command than the author intended,
because you have the wrong mental model of its purpose.

| after all, if you ask "awk" to print given fields, it
| does what you expect.

And again: cut is not filling things in. It's cutting things out.
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Peeve: Going to our favorite breakfast place, only to find that they were
hit by a car...AND WE MISSED IT.
- Don Baldwin, <donb@netcom.com>

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 10:21 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org