按第二个值对文本文件进行排序 [英] Sorting a text file by the second value

查看:140
本文介绍了按第二个值对文本文件进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道notepad ++中是否有一个选项可以按第二个值对文本文件进行排序.

I was wondering if there is an option in notepad++ to sort a text file by the second value.

我有一个看起来像这样的txt:

I have a txt that looks like this :

('sinon', 143)
('serais', 113)
('sens', 107)
('se', 323)
('sans', 113)
('sais', 702)
('sa', 137)
('s', 382)
('rien', 619)
('quoi', 611)

我试图按数字的值对它进行排序,而不是使用记事本按字母顺序排序,但到目前为止没有成功.我也尝试了一些python,但是由于我不太擅长编码,所以在这里没有找到.

I tried to sort it by the value of the number and not alphabetically with notepad but no sucess so far. I also tried a bit of python but as I'm not really good at coding I didn't suceed here.

推荐答案

Notepad ++可以轻松进行排序.该方法是在进行排序之前先修改每行,然后再进行修改.

Notepad++ can easily do the sorting. The method is to modify each line before doing the sort and then modify the lines again afterwards.

在这种情况下,只需将数字前的所有内容移到行尾即可.做一个正则表达式将所有更改的^(.*, )(\d.*)$替换为\2\1.这会将输入文本更改为

For this case just move everything before the number to the end of the line. Do a regular expression replace all changing ^(.*, )(\d.*)$ to \2\1. This changes the input text to be

143)('sinon', 
113)('serais', 
107)('sens', 
323)('se', 
113)('sans', 
702)('sais', 
137)('sa', 
382)('s', 
619)('rien', 
611)('quoi', 

然后使用菜单=>编辑=>行操作=>对行进行排序,将它们按整数升序进行排序.最后,以原始形式重写这些行.用正则表达式将所有更改的$^(.*\))(.*)替换为\2\1.

Then do the sort using menu => Edit => Line operations => Sort lines as integers ascending. Finally rewrite the lines in their original form. Do a regular expression replace all changing $^(.*\))(.*) to \2\1.

这篇关于按第二个值对文本文件进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆