问题描述:

I have a file formatted as such:

...

[ strNADPplus ]

3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457

3458 3459 3460 3461 3462 3463 3464 11153 11154 11155 11156 11157 11158 11159 11160

5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269

5270 5271 5272 5273 5274 5275 5276 5277 12964 12965 12966 12967 12968 12969 12970

5360 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070

5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375

5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414

5415 5416 5417 5418 5419 5420 5421 13110 13111 13112 13113 13114 13115 13116 13117

5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478

5479 5480 5481 5482 5483 5484 5485 5486 13173 13174 13175 13176 13177 13178 13179

5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 13557 13558 13559 13560

5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 13683 13684 13685 13686

6021 6022 6023 6024 6025 6026 6027 6028 6029 13718 13719 13720 13721 13722 13723

6339 6340 6341 6342 6343 6344 6345 6346 6347 14044 14045 14046 14047 14048 14049

...

I want to sort the numbers in that block of lines to have something that looks like:

1 2 3 4

7 8 9 100

101 121 345

346 348 10232

16654 ...

I first tried with :4707,4743%sort n (4707 and 4743 are the lines of that block), but I was only able to sort the first values of each line.

I then tried to join the selection and sort the line: visual mode + J and :'<,'>sort n.

But it doesn't sort correctly.

3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 11153 11154 11155 11156 11157 11158 11159 11160 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 12964 12965 12966 12967 12968 12969 12970 5360 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 13110 13111 13112 13113 13114 13115 13116 13117 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 13173 13174 13175 13176 13177 13178 13179 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 13557 13558 13559 13560 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 13683 13684 13685 13686 6021 6022 6023 6024 6025 6026 6027 6028 6029 13718 13719 13720 13721 13722 13723 6339 6340 6341 6342 6343 6344 6345 6346 6347 14044 14045 14046 14047 14048 14049 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 15124 15125 15126 15127 15128 15129 15130 15131 15132 15133 15134 15135 15136 7502 7503 7504 7505 7506 7507 7508 7509 15208 15209 15210 15211 15212 15213 15214 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 15377 15378 15379 15380 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 5254 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 5463 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 6334 6335 6336 6337 6338 14050 14051 14052 14053 14054 14055 14056 14057 7414 7415 7416 7417 7418 7419 7420 15137 15138 15139 15140 15141 15142 15143 15144 15145 15146 15147 7498 7499 7500 7501 15215 15216 15217 15218 15219 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393 15394 15395 15396 15397

How do I sort everything and keep that layout?

网友答案:

I would simply use standard external unix tools:

:'<,'>!tr ' ' '\n' | sort -n | tr '\n' ' ' | fold -w 15 -s

This wraps lines to 15 characters.

:'<,'>!tr ' ' '\n' | sort -n | paste -d' ' - - -

This wraps to 3 numbers per line.

相关阅读:
Top