0

I have to join two lines. One of them has point end of it to the previous one in whole text example:

line1:hello
line2:goodbye.

I need to change it to:

line1: hello goodbye.

I have to remove every 3rd line (multiples of 3, like 3,6,9,12,15,18,21,... lines) of this huge text.

This is what I want to do.

First Task:

  • check every line

  • if it ends with a period . go to the next line,

  • if it doesn't end with period . join the next line to current line.

Each line doesn't have line number lable, they begin with normal words.

Second Task

  • from the start every 3rd line is rubbish and should be removed

  • the first task must also be done because in some parts the 3rd sentence is divided into 2 lines, so first I have to join the line completely which divided into 2 line then I perform the second task.

I use windows 7. I can use notepad++ and ultraedit

1 Answer 1

0

First task I'd do in Notepad++, using regular expression search&replace:

  • Open "Search" > "Replace..."
  • As "Find what:", enter "([^\.])\r\n" (without the quotation marks)
    • Meaning of the Regex: Find a line that ends with something different than a "."
    • Note: If the document has Linux file endings, you must use just "\n" instead of "\r\n".
  • As "Replace with:", enter "\1 " (without the quotation marks; make sure to also copy the space after "\1")
  • As "Search Mode", select "Regular expression"
  • Click "Replace All"

Input:

hello
goodbye.
hello
hello
goodbye.
hello.
goodbye.

Output:

hello goodbye.
hello hello goodbye.
hello.
goodbye.

The second task can be done with an even longer regex:

  • Open "Search" > "Replace..."
  • As "Find what:", enter "(([^\r\n]*\r\n){2})[^\r\n]*\r\n" (without the quotation marks)
    • Meaning of the Regex: Find a block of three lines.
    • Note: Again, if the document has Linux file endings, you must use just "\n" instead of "\r\n".
  • As "Replace with:", enter "\1" (without the quotation marks)
  • As "Search Mode", select "Regular expression"
  • Click "Replace All"

Input:

hello goodbye.
hello hello goodbye.
sdlfj sdgf.
hello.
goodbye.
(/%&/$&=)?)=´?&%.
goodbye goodbye.
bye.
sldfjsdökl.
hello.

Output:

hello goodbye.
hello hello goodbye.
hello.
goodbye.
goodbye goodbye.
bye.
hello.

Note: In both examples I assumed that there is no trailing whitespace. If there is, you'd need to strip that first, for example by regex-replacing (like above) "\s*$" with "" (without the quotation marks).

1
  • Thank you so much for this big help,It does work, I didn't know it is possible to do with "Regular expression", I have to read about more, thanks a lot, ciao Mar 15, 2015 at 9:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .