[Discuss] cocat for linux

Clarke Brunsdon crimson at uvic.ca
Fri Jun 9 15:27:40 PDT 2006


#!/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
~Clarke

On Fri, 2006-06-09 at 14:14 -0700, p.willis at telus.net wrote:
> 
> Hello,
> 
> Is anyone interested in a cocat utility for linux?
> I'll post the source if it's of use.
> 
> I needed one for soemting I was working on...
> 
> The program works like 'cat'  except when you
> give it multiple file names it concatinates successive lines from
> each file onto a single line until all files are finished.
> Columnar output is delimited by a single space character.
> 
> ie:
> 
> filea contains:
> 1
> 2
> 3
> 
> fileb contains:
> A
> B
> C
> 
> filec contains:
> !
> #
> $
> 
> cocat filea fileb filec
> 
> output:
> 
> 1 A !
> 2 B #
> 3 C $
> 
> 
> Peter
> 
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss



More information about the Discuss mailing list