[Discuss] cocat for linux

pw p.willis at telus.net
Fri Jun 9 17:52:08 PDT 2006


Clarke Brunsdon wrote:
> On Fri, 2006-06-09 at 15:46 -0700, p.willis at telus.net wrote:
> 
>>Quoting Clarke Brunsdon <crimson at uvic.ca>:
>>
>>
>>>#!/usr/bin/python
>>>import sys
>>>files = []
>>>for file in sys.argv[1:]:
>>>        files.append( open (file, 'r') );
>>>haslines = 1;
>>>while(haslines):
>>>        haslines = 0
>>>        thisline = ""
>>>        for file in files:
>>>                line = file.readline()
>>>                haslines = haslines or line
>>>                thisline = thisline + " "  + line[:-1]
>>>        print thisline[1:]
>>>
>>>
>>>14 lines, 2 minutes
>>
>>
>>Great!
>>What does it do if the files have different numbers of lines?
> 
> 
> it partitions your hard drive.
> 
> 
>>cocat is written in C and does error checking, has selectable delimiter.
>>I do have one buffer to make resizing dynamic on though.
>>91 lines , 18 minutes (including testing) 
> 
> 
> i bet it runs exceptionally fast
> 

I think the usefulness of this command line app is being missed.
(Or people honestly don't care....which is most likely)

I'll explain anyway.

I was looking for a way to pipe the outputs of multiple programs into
one program simultaneously as a single stream on a single command line.

ie: Simple example

cat file_a |-------\
                     \..............|program
                     /
cat file_b |-------/

using cocat:

cocat -d <some_delimiter> file_a file_b |\
awk -F "<some_delimiter>" {'print $1 $2; print $2 $1; print $1 "\n" $2 
"\n"'}


I'm not sure that's any more clear....


Peter


More information about the Discuss mailing list