Re: join two files
Davide Brini <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 16 May 2013 08:57:40 -0700, Jim Hill <[email protected]> wrote: > On 05/15/2013 11:51 PM, MOKRANI Rachid wrote:> Hi, > > > > Well this is a good solution and it work. You should send it to the > > list so that others can benefit too. > > ok, happy to. > > awk -vFS=\; -vOFS=\; '{ printf("%04d;%s\n",$1,$0) }' file1>@file1 > awk -vFS=\; -vOFS=\; '{ printf("%04d;%s\n",$1,$0) }' file2>@file2 > join -a1 -t\; -o 1.2,1.3,2.3 -eN/A @file2 @file1 Why not the simpler and single-pass awk -F ' *; *' ' NR == FNR { a[$1] = $2 next } { f = ( ($1 in a) ? a[$1] : "N/A" ) print $0 " " f ";" } ' file1 file2 I assume spacing around semicolons isn't relevant; in case it is, the modifications are obvious (although I'd consider such an environment slightly broken). -- D.