This is my python script for sorting by column a csv file read from stdin:
with sys.stdin as csvfile:
reader = csv.reader(csvfile, delimiter=',')
sortedlist = sorted(reader, key=operator.itemgetter(2))
for row in sortedlist:
print(','.join(row)),
print('\n'),
I run the command in order to sort by 3rd column(zero indexed is 2):
./sorter1.py < test.csv > test_sorted.csv
and the sorted file test_sorted.csv is:
31,53,101,122
88,95,103,59
66,58,104,50
93,46,105,52
88,88,118,107
**115,57,31,34**
110,87,36,63
32,108,36,107
75,35,57,35
99,46,57,28
41,35,67,59
108,99,98,35
36,66,98,60
It is like sorted two files and merged it. Is it a matter of buffer size of the reader or a matter of sorted method?
This sorts alphabetically not numerically
columndefined and what value is it?