Unix Programming - UUOC not so U

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2006 > UUOC not so U





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author UUOC not so U
Pascal Bourguignon

2006-10-23, 1:16 pm

John Gordon <gordon@panix.com> writes:

> In <12jm11u83jadc5c@corp.supernews.com> gordonb.3atgq@burditt.org (Gordon Burditt) writes:
>
>
>
> UUOC = Useless Use of Cat. Using the "cat" command when you don't need to:
>
> cat textfile | some_program
>
> when you could just as easily do without the cat:
>
> some_program < textfile


But it's not as easy. It's much harder to put the input _after_ the filter.


If you want to remove pgm0 (_ indicates the cursor position):

start with: _pgm0 < input | pgm1 | pgm2 | pgm3 > output
- delete pgm0: _< input | pgm1 | pgm2 | pgm3 > output
- cut < input: _| pgm1 | pgm2 | pgm3 > output
- delete |: _pgm1 | pgm2 | pgm3 > output
- forward over pgm1
(including arguments!): pgm1 _ | pgm2 | pgm3 > output
- paste < input: pgm1 < input | pgm2 | pgm3 > output
-----------------------------
= 5 basic edits.


start with: _cat<input | pgm0 | pgm1 | pgm2 | pgm3 > output
- skip over to pgm0: cat<input | _pgm0 | pgm1 | pgm2 | pgm3 > output
_ delete pgm0 |: cat<input | pgm1 | pgm2 | pgm3 > output
------------------------------
= 2 basic edits.


If you want to add pgm0 it's even worse:

start with: _pgm1 < input | pgm2 | pgm3 > output
- forward over pgm1 and args: pgm1 _< input | pgm2 | pgm3 > output
- cut < input: pgm1 _ | pgm2 | pgm3 > output
- back to BoL: _pgm1 | pgm2 | pgm3 > output
- type in pgm0: pgm0 pgm1 | pgm2 | pgm3 > output
- paste < input: pgm0 < input pgm1 | pgm2 | pgm3 > output
- type in |: pgm0 < input | pgm1 | pgm2 | pgm3 > output
------------------------------
= 6 basic edits

start with: _cat<input | pgm1 | pgm2 | pgm3 > output
- skip over to pgm1: cat<input | _ pgm1 | pgm2 | pgm3 > output
- type pgm0 |: cat<input | pgm0 | _ pgm1 | pgm2 | pgm3 > output
------------------------------
= 2 basic edits.


So clearly using cat<input| ... |cat>output is superior.
We could even add syntax suggar to remove the cats.

input< ... pgm_i | pgm_i+1 ... >output


--
__Pascal Bourguignon__ http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
Keith Thompson

2006-10-23, 7:21 pm

Pascal Bourguignon <pjb@informatimago.com> writes:
> John Gordon <gordon@panix.com> writes:
>
> But it's not as easy. It's much harder to put the input _after_ the filter.

[snip]

So write it as

< textfile some_program

Yes, it really works.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
sjdevnull@yahoo.com

2006-10-24, 7:21 am

Pascal Bourguignon wrote:
> John Gordon <gordon@panix.com> writes:
>
>
> But it's not as easy. It's much harder to put the input _after_ the filter.
>


The example was misleading, putting the input after the filter and
using a redirect instead of cat are seperate issues. You can avoid
forking an unnecessary process with:

< textfile some_program

The most common time to use cat is when you need to catenate 2 or more
files--that's where the name "cat" comes from:

cat textfile1 textfile2 | some_program

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com