If i have to sort following rows on the basis of values on left of '='. But the sorting should expand the selection to column after '=' simultaneously. Thtz is we dnt have to sort column after '=' ::
50599=1000000
50454=00000054
50080=00005464
50098=00000875
50661=00000665
50788=10000035
50988=10000006
50994=10000656
57009=00000005
57022=10000008
57040=10000005
57000=10000005
57060=10000089
57067=10005640
57102=00000765
57190=00000867
This needs to be done in 'VI' editing the file.
RESULT should be ::
50080=00005464
50098=00000875 ...etc.
To sort lines of text files, we use the sort command in the Linux system. The sort command is used to prints the lines of its input or concatenation of all files listed in its argument list in sorted order. The operation of sorting is done based on one or more sort keys extracted from each line of input.
In normal mode or in insert mode, press Alt-j to move the current line down, or press Alt-k to move the current line up. After visually selecting a block of lines (for example, by pressing V then moving the cursor down), press Alt-j to move the whole block down, or press Alt-k to move the block up.
If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.
Try:
:%!sort
It will sort according the whole line alphabetically. If you want to sort numerically (i.e. the number in the first column can have different widt), then try:
:%!sort -n
Don't worry about the =
, it will not modify any line, it will just change their order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With