Remove every other newline

那年仲夏 提交于 2019-12-30 18:59:52

问题


I have a list of data in text format that looks as follows

Name1 Name2

location job date amount

Name1 Name2

location job date amount

Name1 Name2

location job date amount

I need to somehow make this into

Name1 Name2 location job date amount

...

I figure there has got to be a way to grab every other newline with either regex or excel. I could write a python script but this file has been a pain and was hoping there would be an easier way to do it.

EDIT: adding what I've tried below:

Sorry, I should have included some code... I tried

([^\n]*\n)[^\n]*\n 

in regex, but that groups the two lines together, I basically would like to grab only the newline between the groups. I have also tried doing this in excel systematically but it doesn't continue to grab every other cell when I drag the box down. It changes from every other cell in the column to every cell once I try to extrude it.


回答1:


Using .Net regex flavoring (should be the same for VBA, but I didn't check), I came up with the following:

Pattern = "([^\n]*)(\n)([^\n]*(\n|\z))"
Replacement = "$1$3"

Basically, catching the first NewLine character in the second capture group and then not returning it in our replacement.

Hope this helps.



来源:https://stackoverflow.com/questions/20572973/remove-every-other-newline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!