[mdlug] UNIX tips: Learn 10 good UNIX usage habits

Clinton V. Weiss cvweiss at gmail.com
Mon Mar 10 20:56:32 EDT 2008


Aaron Kulkis wrote:
> Michael Corral wrote:
>   
>> 2008-03-10, Monsieur Robert Citek a ecrit:
>>     
>>> contrast the output of these commands:
>>>
>>> $ cat /etc/passwd /etc/group | grep root
>>> $ grep root /etc/passwd /etc/group
>>>       
>> grep -h root /etc/passwd /etc/group
>>
>> That will give the same output as the cat+pipe version.
>> So calling cat is unnecessary in this example, since the one grep
>> command does the same as two commands and a pipe.
>>
>> In my experience I've found that calling cat is unnecessary about 95%
>> of the time.
>>
>>     
>
> The only times cat is necessary...
>
> 1: you want the to use one of the flags of cat, such as:
>     cat -n file1 | cmd
>     to prepend each line with a line number.
>
> 2: Multiple files to be processed as a single input stream.
>
>     cat file1 file2 [file3...] | cmd

3. I want to quickly read the contents of the file.

Clinton =)



More information about the mdlug mailing list