How to merge two files in awk??

Geoff Clare gwc at root.co.uk
Thu Jan 24 02:18:03 AEST 1991


In article <1991Jan19.194124.2335 at convex.com> tchrist at convex.COM (Tom Christiansen) writes:
> : 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...
> Someone out there may have as paste solution, but I didn't see one.  

In <25041:Jan2017:21:1491 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:

}Is that a challenge?

}  #!/bin/sh
}  # untested, but too simple to fail in strange ways
}  # type X as tab
}  awk '{ print $1; print $2; print $3 }' < "$1" > /tmp/file1.$$
}  awk '{ print $1; print $2; print $3 }' < "$2" > /tmp/file2.$$
}  paste /tmp/file1.$$ /tmp/file2.$$ | (
}  while read i
}  do
}    read j; read k
}    echo "$iX$jX$k"
}  done
}  )
}  rm /tmp/file1.$$ /tmp/file2.$$


That is really gross!

Try this:

    paste "$1" "$2" | awk '{print $1, $4, $2, $5, $3, $6}'

-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273



More information about the Comp.unix.questions mailing list