问题
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:
Open "Search>Replace" dialog
In the "Find What" field place the string "(country=\w*)\r\n(name=\w*)" without quotes.
In the "Replace With" field palce the string "(\1) (\2)", also without quotes.
Mark the "Regular Expression" Search Mode.
Press "Find Next" to test it.
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