I am trying to get the last column into an NxN table, but there are missing zero values. To get to the table I think I can just use awk/xarg, but would need the missing zeros? The first two columns are just identifiers in the original raw data files. In this case the first column goes from 1 to 2, the second column goes 1 to 5 and the last column is the actual data where missing zeros are needed to be inserted. The identifiers are always the same length as it corresponds to a row and column. In practice there are actually 1000's of lines of data but the above example is a reduced example and would work for the true data set.
Edit: To clarify, by 1000's I mean to first column would range from 1-1000's and the second would also range from 1-1000's. But the lines are missing that I want to add with a zero value in the third column. However I think if it can be done for this example below then it can be done for a larger file.
data set
1 1 5
1 2 4
1 4 2
2 1 5
2 2 6
2 3 5
Expected data set
1 1 5
1 2 4
1 3 0
1 4 2
1 5 0
2 1 5
2 2 6
2 3 5
2 4 0
2 5 0
I tried using a suggestion from here using python Credit - heemayl
with open('test.sum') as f:
check = 0
for line in f:
if int(line.split()[1]) == check + 1:
check = int(line.split()[1])
print line.rstrip()
else:
check = int(line.split()[1])
print int(line.split()[1]) - 1, '\t0'
print line.rstrip()
print int(line.split()[1]) + 1, '\t0'
print int(line.split()[1]) + 2, '\t0'
But it appears it adds a zero between my rows where 1 and 2 meet (in the first column) and also I can't seem to get it to work on 3 columns. Open to awk or any simplier ideas however!
Many thanks for any help!