cat file1:
a
b
c
d
e
cat file2:
a 10
c 20
e 30
f 40
The desired output file is:
a 10
b
c 20
d
e 30
f 40
I've tried using awk but I ended with all the lines of file1 repeated. Many thanks
Read in both files and hash them to an array (a). If you read in file1 before file2 the collisions will be in your favor. In awk:
$ awk '{a[$1]=$0} END{for(i in a) print a[i]}' file1 file2
a 10
b
c 20
d
e 30
f 40
Explained:
{
a[$1]=$0 # hash all records to a
}
END { # after processing both files
for(i in a) # iterate thru every key in a
print a[i] # and output their values
}
Due to the nature of for(i in a) the output order is random.
[linux] joinor[bash] joinand readman join. Good luck. - shellter