tags:

views:

40

answers:

3

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.
+1  A: 

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.

eumiro
Vim has the internal sort command: `:%sort n`
Benoit
+1  A: 

You can do the following to see the sorted output:

:!sort %

Explanation:

  • : : to enter ex mode.
  • ! : allows you to run a shell command.
  • % : the name of the file currently open.

To sort the file by changing it you can redirect its output to a temp file and then copy its content back to the original file:

:!(sort %>/tmp/tmp;cp -f /tmp/tmp %)
codaddict
Hmm, the file got corrupted. I forgot to tell you sthin : this is a xml file which has some attributes in it like ::
Ashish
A: 

Hmm, the file got corrupted. I forgot to tell you sthin : this is a xml file which has some attributes in it like ::

    `<attribute name="Username" type="java.lang.String">Hello</attribute>` 
            `<attribute name="Password" type="java.lang.String">hello</attribute>`  

    `<attribute name="ID" type="java.lang.String">T00747</attribute>`  
            `<attribute name="IdMap" type="java.util.Properties">`

50599=1000000
50454=00000054
50080=00005464
50098=00000875
50661=00000665
50788=10000035
50988=10000006
50994=10000656

     `</attribute>`

     `<attribute name="SubIdMap" type="java.util.Properties">`

50599=1000000
50454=00000054
50080=00005464
50098=00000875
50661=00000665
50788=10000035
50988=10000006
50994=10000656

      `</attribute>'

      `<!--attribute name="OPSubIdMap" type="java.util.Properties">`

50599=1000000
50454=00000054
50080=00005464
50098=00000875
50661=00000665
50788=10000035
50988=10000006
50994=10000656

Now this file has numbers within attributes. We need to sort them.

NOTE : When I tried you formula, the file only left with sort numbers at one place and rest attributes separated in the file. If you could see the values are repeating in the attributes and we need to sort them in the attribute itself.

Ashish