I do have two files:
File1
12 abc
34 cde
42 dfg
11 df
9 e
File2
23 abc
24 gjr
12 dfg
8 df
I want to merge files column by column (if column 2 is the same) for the output like this:
File1 File2
12 23 abc
42 12 dfg
11 8 df
34 NA cde
9 NA e
NA 24 gjr
How can I do this?
I tried it like this:
cat File* >> tmp; sort tmp | uniq -c | awk '{print $2}' > column2; for i in
$(cat column2); do grep -w "$i" File*
But this is where I am stuck…
Don’t know how after greping I should combine files column by column & write NA where value is missing.
Hope someone could help me with this.
Since I was testing with
bash3.2 running assh(which does not have process substitution assh), I used two temporary files to get the data ready for use withjoin:With process substitution, you could write:
If you want the data formatted differently, use
awkto post-process the output: