Notepad++ Merge 2 lines into 1 line

自作多情 提交于 2020-12-02 07:16:35

问题


I have the following text;

country=france
name=jean
country=germany
name=michael
country=england
name=jack

I want it to look like;

country=france name=jean
country=germany name=michael
country=england name=jack

How do I do this in Notepad++?


回答1:


Use the extended replace functionality and replace "\r\nname" with " name"

Substitute appropriate line ending characters for \r\n depending on the file.

If it is from windows, use \r\n

If it is from unix, use \n

If it is from mac, use \r




回答2:


Choose Edit → Line Operations → Join Lines from the menu or

Select the lines & press Ctrl + J --> Easiest option :)




回答3:


  1. Open "Search>Replace" dialog

  2. In the "Find What" field place the string "(country=\w*)\r\n(name=\w*)" without quotes.

  3. In the "Replace With" field palce the string "(\1) (\2)", also without quotes.

  4. Mark the "Regular Expression" Search Mode.

  5. Press "Find Next" to test it.

  6. If 2 lines starting with country=XX and name=YY are selected, then press "Replace All".

If you're not using windows, you'll have to use only \n or \r, depending if you're using linux/unix or mac.

Notepad++ Uses Posix Regular expressions. You can refer to any standard Posix Regex reference, like this one or this one.




回答4:


Want to add in case it can help with similar case:
to replace lines in file when previous line digit and second text

1
text
2
text

based on Filipe Fedalto answer regex will be:

find:(\d+)\r\n
replace:(\1)


来源:https://stackoverflow.com/questions/11084086/notepad-merge-2-lines-into-1-line

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