How to delete a specific line of a paragraph in AppleScript, while retaining the original format of the text? I have a text variable of class text that shows something like this when it is returned:

"
This is sentence 1.
This is sentence 2.
This is sentence 3.
This is sentence 4."


I want to be able to delete specific lines from the text, without affecting the rest of the variable.

For example: delete {1, 3} to get this result:

"This is sentence 1.
This is sentence 3.
This is sentence 4."




The method described in this answer has a serious bug:

"How to delete a specific line of a paragraph in AppleScript?"

The linked method to delete lines in a paragraph actually converts all linefeeds in the text variable to returns. In other words, it is impossible to run this code more than once on the same variable.

For example, the following code:

set varText to "
This is sentence 1.
This is sentence 2.
This is sentence 3.
This is sentence 4."
set varText to do shell script "sed -e '1d;3d' &lt;&lt;&lt; " &amp; quoted form of varText
-- Employing the same method on the same variable:
set varText to do shell script "sed -e '1d;3d' &lt;&lt;&lt; " &amp; quoted form of varText
return varText


returns

""

Since this method only works correctly if the lines of the text variable are the product of a linefeed (as it should), the problem is not that this method fails to perceive a return as a new line (as I had originally claimed in this question). The problem is that this code introduces a return to the text variable in the first place.



Thus, I want a solution that will allow me to run the same text variable through the solution more than once in the same AppleScript.

In other words, I am looking for a method to remove a specific line from a paragraph that does not have this bug and does not insert a return anywhere in the text.
Example:

set varText to "
This is sentence 1.
This is sentence 2.
This is sentence 3.
This is sentence 4."

set varText to do shell script "sed -e '1d;3d' &lt;&lt;&lt; " &amp; quoted form of varText


Returns:

"This is sentence 1.
This is sentence 3.
This is sentence 4."




Update: As a result of a discovery mentioned in the Edit: of How to delete a specific line of a “return”-based paragraph in AppleScript?, let me make the following statement:

NOTE: Unfortunately what's returned in this case has carriage return (x0D) characters instead of the expected new line (x0A) characters and in my opinion is a bug!

It's a bug because: The do shell script "sed ..." command when run in Terminal with that varText returns with \n (x0A) not \r (x0D) as it's supposed to. Even the compiled do shell script "sed ..." command in Script Editor still has \n (x0A) not \r (x0D) however why it's being returned with \r (x0D) intend of the expected \n (x0A) is a mystery to me at the moment and I'm going to consider this an AppleScript bug since it not mirroring the expected behavior of the same when run in Terminal.

So, to account for the bug in the results of the do shell script "sed ..." command, this is how I'd handle it. After the do shell script "sed ..." command use the following lines of code:

set newLine to "\n"
set varText to paragraphs of varText
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to newLine
set varText to varText as string
set AppleScript's text item delimiters to oldTID


Now what's returned contains new line (x0A) characters as it should have to begin with if there wasn't this bug, not carriage return (x0D) characters.



Note: When compiled, the set newLine to "\n" line of code will show as below:

set newLine to "
"