If I sort a file, I want save it in the new one. I use for this just:
sort -nk{fieldnumber} test.json > testsort.json
In the output the columns are shuffled and the column, which I have sorted, is in random order (not ascending). Why is it happen? Also, I want split this sorted file in many parts. I wish all parts are also sorted by the column, like here:
partaa
{'a':'a', 'b':'b', 'c':1}
{'a':'a', 'b':'b', 'c':1}
{'a':'a', 'b':'b', 'c':2}
partab
{'a':'a', 'b':'b', 'c':2}
{'a':'a', 'b':'b', 'c':3}
{'a':'a', 'b':'b', 'c':3}
partac
{'a':'a', 'b':'b', 'c':4}
{'a':'a', 'b':'b', 'c':5}
{'a':'a', 'b':'b', 'c':6}
I use for it
split -l 100 testsort.json part
Anyway, I have the all time the shuffled, unordered output. (for example some value from partac could be lesser then from partab)
PS
Thank you, I have found the problem someself. The input was corrupt, because some lines have additional fields.
{'a':'a', 'b':'b', 'c':2}
{'a':'a', 'b':'b', 'c':1}
{'a':'a', 'b':'b', 'c':2}
{'a':'a', 'b':'b', 'd':'d', 'c':1}
{'a':'a', 'b':'b', 'c':3}
{'a':'a', 'b':'b', 'f':'f', 'c':4}
I construct next regular expression, which search for certain field, take the numeric values, bring them in the front and sort them
sed -e 's/^\(.*columnname\)\([^,]*\)/\2\t\1\2/;s/^[" :]*//' test.json | sort -nk1 |sed -e 's/^[^{]*//' > testSort.json
'f':'f',
makes itcomplicated withsort
alone; It is not made for this kind of data. Sosed
is a good idea.