So compare the first columns and collect the value for that from files. if the entry is missing then it should give -. Most of the entries will be shared between files but some of them are missing. I have around 8 files like this with two columns .
@sk1418: thanks for the help, but I may have more file then I think i have to extent the script with more ARGIND check. Is it possible to make it some loop or something? I think I have to check with ARGIND==0 ?
Even then I am only getting the last file counts and for the rest just a - .
hi, this script is just for 3 or less then 3 files as input. If you have more files, the logic needs to be changed as well, not only the ARGIND part. say you have 10 files, then one line could be
g5.1 - - - - - 7 - - - -
the script above cannot give you that output. So "extend" doesn't work. you have to rewrite.
awk can do this, but not so easy, at least I haven't thought a shortcut for that, glad to know if someone has. You may try write a python script. I think that wouldn't be complicated.
---------- Post updated at 14:45 ---------- Previous update was at 14:07 ----------
here is the py script to do your job.
#!/usr/bin/python
files=['file1','file2','file3']
dict={}
len = files.__len__()
for s in files:
idx = files.index(s)
f = open(s)
line = [x.replace("\n","") for x in f.readlines()]
for l in line:
k,v = l.split(" ")[0], l.split(" ")[1]
if(not dict.has_key(k)):
dict[k] = list("-"*len)
dict[k][idx] = v
f.close()
keys = dict.keys()
keys.sort()
for k in keys:
print k+" "+ reduce(lambda x,y: x + " " + y,dict[k])