如何从垂直名称值对集转换 csv 列表(水平)
我有一个这样的列表:
GTPYANJ 695848
GTPYANJ 27811
FPORTAL3 432532
我想使用正则表达式将其变成这样:
GTPYANJ,695848,27811
FPORTAL3,432532
建议?
I have a list like this:
GTPYANJ 695848
GTPYANJ 27811
FPORTAL3 432532
I want to turn it into this using regular expressions:
GTPYANJ,695848,27811
FPORTAL3,432532
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
加载到 jEdit(或 Notepad++,或其他可以通过正则表达式搜索/替换的编辑器)中。
步骤 1 是确保分隔符是制表符。
然后,搜索
并替换为
重复查找/替换所有,直到不再匹配被发现。
load into jEdit (or Notepad++, or some other editor that can search/replace via regex.
Step 1 is to make sure that the delimiter is a tab.
Then, search for
and replace that with
Repeat the find/replace all until no more matches are found.
Perl 单行代码:
比尝试将多遍正则表达式拼凑在一起要容易得多,在正确之前,它很可能会中断几次,并且这取决于要排序的数据,并且可能需要第二个正则表达式来重新格式化一切都在最后……
Perl one-liner:
Much easier than trying to hobble together a multi-pass regex that will most likely break a couple of times before you get it right, and which depends on the data being sorted, and which might require a second regex to reformat everything at the end...