Remove every other newline

2019-06-22 01:31发布

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条回答
Rolldiameter
2楼-- · 2019-06-22 02:17

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.

查看更多
登录 后发表回答