How to merge two files in awk??

Mike Faber sleepy at wybbs.mi.org
Tue Feb 5 01:16:23 AEST 1991


In article <1070 at mwtech.UUCP> you write:
>In article <3404 at d75.UUCP> @xlab1.uucp () writes:
>> Supposing I have two files with three collumns in each. How do
>> I merge the files and generate a single file with six or more 
>> collumns using shell script?  for example if File A has collumns a, c, e 
>> and File B has collumns b, d, f. I want to generate File C
>> with collumns a,b,c,d,e,f.  Also it would be nice to be able to
>> using the arithematic feature in awk...
>
>IMHO this is not feasable with OLD "awk" for LARGE files.

[Good discussion of old/new awk and solution]

Aren't we overlooking the easy solution here?

paste -d"|" filea fileb | awk -F"|" ' { printf("%s %s %s %s %s %s\n", \
$1,$3,$5,$2,$4,$6) } ' >outputfile

OK, it's brute force, but it's simple, easy to read, and flexible, in case the
file changes.

--
Michael Faber
sleepy at wybbs.uucp



More information about the Comp.unix.questions mailing list