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, 05:44 AM
"Robert P. J. Day"
 
Default why does "cut" print fields in original order?

On Wed, 21 Nov 2007, Ed Greshko wrote:

> Robert P. J. Day wrote:
> > nitpicky, yes, but it occasionally irritates me that "cut" will
> > print fields, not in the order you specify them with the "-f" option,
> > but in the original order in the source text, to wit:
> >
> > $ cut -d: -f1,7 /etc/passwd
> > root:/bin/bash
> > bin:/sbin/nologin
> > daemon:/sbin/nologin
> > ...
> >
> > $ cut -fd: -f7,1 /etc/passwd
> > root:/bin/bash
> > bin:/sbin/nologin
> > daemon:/sbin/nologin
> > ...
> >
> > is there really a reason that cut refuses to acknowledge the
> > order of the fields as supplied by the user? some historical
> > reason, perhaps, that we can now all make fun of and wonder what
> > they were smoking at the time?
>
> I don't see any indication from the man page that would lead one to
> believe that cut will print in the order listed. I think you are
> simply implying a behavior that was never intended.

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? it would
seem that that would be an obvious enhancement and, certainly, that
would be more intuitive behaviour, no?

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, 05:50 AM
Ed Greshko
 
Default why does "cut" print fields in original order?

Robert P. J. Day wrote:
> On Wed, 21 Nov 2007, Ed Greshko wrote:
>
>> Robert P. J. Day wrote:
>>> nitpicky, yes, but it occasionally irritates me that "cut" will
>>> print fields, not in the order you specify them with the "-f" option,
>>> but in the original order in the source text, to wit:
>>>
>>> $ cut -d: -f1,7 /etc/passwd
>>> root:/bin/bash
>>> bin:/sbin/nologin
>>> daemon:/sbin/nologin
>>> ...
>>>
>>> $ cut -fd: -f7,1 /etc/passwd
>>> root:/bin/bash
>>> bin:/sbin/nologin
>>> daemon:/sbin/nologin
>>> ...
>>>
>>> is there really a reason that cut refuses to acknowledge the
>>> order of the fields as supplied by the user? some historical
>>> reason, perhaps, that we can now all make fun of and wonder what
>>> they were smoking at the time?
>> I don't see any indication from the man page that would lead one to
>> believe that cut will print in the order listed. I think you are
>> simply implying a behavior that was never intended.
>
> 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? it would
> seem that that would be an obvious enhancement and, certainly, that
> would be more intuitive behaviour, no?

You would have to ask the writers (David Ihnat, David MacKenzie, and Jim
Meyering).

I'd say it was "working as designed" and that we humans sometimes are too
intuitive. :-)

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

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? it would
> seem that that would be an obvious enhancement and, certainly, that
> would be more intuitive behaviour, no?

It would be fairly trivial to "roll your own" if you require that functionality.

--
MELVILLE THEATRE ~ Melville Sask ~ http://www.melvilletheatre.com

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

Robert P. J. Day wrote:


nitpicky, yes, but it occasionally irritates me that "cut" will
print fields, not in the order you specify them with the "-f" option,
but in the original order in the source text, to wit:

$ cut -d: -f1,7 /etc/passwd
root:/bin/bash
bin:/sbin/nologin
daemon:/sbin/nologin
...

$ cut -fd: -f7,1 /etc/passwd
root:/bin/bash
bin:/sbin/nologin
daemon:/sbin/nologin
...

is there really a reason that cut refuses to acknowledge the
order of the fields as supplied by the user? some historical
reason, perhaps, that we can now all make fun of and wonder what
they were smoking at the time?

I don't see any indication from the man page that would lead one to
believe that cut will print in the order listed. I think you are
simply implying a behavior that was never intended.


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? it would
seem that that would be an obvious enhancement and, certainly, that
would be more intuitive behaviour, no?


You need some reason to type:
sed -e 's/(.*).*).*).*).*).*).*)/7:1/'

--
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, 06:12 AM
"Robert P. J. Day"
 
Default why does "cut" print fields in original order?

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?
> > it would seem that that would be an obvious enhancement and,
> > certainly, that would be more intuitive behaviour, no?
>
> 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!"

i'm just curious what kind of thinking went into doing something so
non-intuitive. after all, if you ask "awk" to print given fields, it
does what you expect. i just can't imagine what sort of thinking went
into cut's behaviour, when doing it "right" the first time seems like
it would have been a no-brainer.

anyway, i know there's always awk when i want something done
correctly.

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:14 AM
"Robert P. J. Day"
 
Default why does "cut" print fields in original order?

On Wed, 21 Nov 2007, Les Mikesell wrote:

> Robert P. J. Day 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?

> You need some reason to type:
> sed -e 's/(.*).*).*).*).*).*).*)/7:1/'

you are a truly sick person, and should seek help.

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:20 AM
Ed Greshko
 
Default why does "cut" print fields in original order?

Robert P. J. Day 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?
>>> it would seem that that would be an obvious enhancement and,
>>> certainly, that would be more intuitive behaviour, no?
>> 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!"
>
> i'm just curious what kind of thinking went into doing something so
> non-intuitive. after all, if you ask "awk" to print given fields, it
> does what you expect. i just can't imagine what sort of thinking went
> into cut's behaviour, when doing it "right" the first time seems like
> it would have been a no-brainer.

I don't feel there is a concept of "right" in this case.

I mean, if you cut fields that have known meanings and retain the order you
still know the meaning of each field and you'd normally deal with them in
that order. IMHO, it doesn't make much sense to cut them, rearrange them,
and then deal with them in an order different from the original order.

But, maybe that is just me. When I deal with an ordered list in one area I
hope that the meaning/order of the list isn't changed in a different area.
Kind of makes keeping things straight difficult....

> anyway, i know there's always awk when i want something done
> correctly.

I think you mean, there is always a more flexible tool...such as awk.

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

Robert P. J. Day 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?



You need some reason to type:
sed -e 's/(.*).*).*).*).*).*).*)/7:1/'


you are a truly sick person, and should seek help.


But it says what you wanted fairly clearly and in much more re-usable
terms that a minimalist tool like cut.


--
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, 01:09 PM
"Mikkel L. Ellertson"
 
Default why does "cut" print fields in original order?

Robert P. J. Day wrote:
> nitpicky, yes, but it occasionally irritates me that "cut" will
> print fields, not in the order you specify them with the "-f" option,
> but in the original order in the source text, to wit:
>
> $ cut -d: -f1,7 /etc/passwd
> root:/bin/bash
> bin:/sbin/nologin
> daemon:/sbin/nologin
> ...
>
> $ cut -fd: -f7,1 /etc/passwd
> root:/bin/bash
> bin:/sbin/nologin
> daemon:/sbin/nologin
> ...
>
> is there really a reason that cut refuses to acknowledge the order
> of the fields as supplied by the user? some historical reason,
> perhaps, that we can now all make fun of and wonder what they were
> smoking at the time?
>
> rday
>
From the man page:

Use one, and only one of -b, -c or -f. Each LIST is made up of one
range, or many ranges separated by commas. Selected input is written
in the same order that it is read, and is written exactly once.

I am not sure, but I suspect that cut just checks to see if the data
being read matches one of the fields it is supposed to match, and it
it does, then it prints it. This would go along with it being
designed as a filter. I suspect that it does not analyze the entire
line, and then print the matched fields, but instead analyzes the
line as it goes, printing the parts that match the filter criteria.

Remember, cut dates back to when resources were limited, and was
designed to be a "building block" to be combined with other programs
in shell scripts to do complicated tasks. As such, it was designed
to perform a simple task quickly, and with minimal resource usage.
There were more complicated programs, with higher resource usage,
for when you need more then it provides.

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, 01:26 PM
Dave Ihnat
 
Default why does "cut" print fields in original order?

On Wed, Nov 21, 2007 at 02:50:03PM +0800, Ed Greshko wrote:
> You would have to ask the writers (David Ihnat, David MacKenzie, and Jim
> Meyering).

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.

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
 

Thread Tools




All times are GMT. The time now is 03:49 PM.

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