Merging two files into one based on the first column?

Here's an AWK version (the sort compensates for AWK's non-deterministic array ordering).

Join file1 file2 Here's an AWK version (the sort compensates for AWK's non-deterministic array ordering): awk '{a$1=a$1 FS $2} END {for (i in a) print I ai}' file1 file2 | sort It seems shorter and more readable than the Perl answer.

Only on *nix systems with GNU coreutils installed, AFAIK. – Jim Garrison Nov 1 '10 at 19:17 @Jim: join has been part of the default install on every Unix-like system I've ever used. Also "core" means "core".

And, based on the OP's tags, I'm assuming a Linux/Unix system. – Dennis Williamson Nov 1 '10 at 19:20 2 @Jim: join is specified by POSIX, and existed long before. – Gilles Nov 2 '10 at 0:00 @Gilles and Dennis: thanks for the info – Jim Garrison Nov 2 '10 at 4:18.

A Perl-solution perl -anE 'push @{$h{$F0}}, $F1; END{ say "$_\t$h{$_}->0\t$h{$_}->1" for sort{$a$b} keys %h }' file_1 file_2 > file_3 Ok, looking at the awk-oneliner this is shorter then my first try and it has the nicer output then the awk-oneliner and it doesn't use the 'pipe sort -n'; perl -anE '$h{$F0}="$h{$F0}\t$F1"; END{say "$_$h{$_}" for sort {$a$b} keys %h}' file_1 file_2 And the one-liners behave different then the join-example if there are entries with no value in the second column in the first file.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions