-   Linux - Newbie (
-   -   Trivial regular expression for replacing "\n.\n" with "\n .\n" (

gregorian 08-23-2009 12:54 PM

Trivial regular expression for replacing "\n.\n" with "\n .\n"
I've written a CGI script that sends mail using sendmail. If a line contains a period(.) only, it ignores anything written after that line as expected. As a solution, I plan on replacing the period with a period and a space if it's on a separate line.

I'm using Perl. This regular expression does not solve my problem:

$body =~ s/\n\.\n/\n\. \n/gm
Any help will be appreciated. Thank you.

colucix 08-23-2009 01:00 PM

You can try the regexp notation for the beginning and the end of the line, that is ^ and $ respectively:

sed 's/^[.]$/. /g' file
Note that you have to embed the dot in a character list (or escape it with backslash), otherwise it is interpreted as "any single character" in a regular expression.

gregorian 08-23-2009 02:36 PM

It didn't work. But thank you for your time :)

I have escaped the . in my original expression. And the variable $body receives text from a form and may contain several newlines. That is why I used the /g and /m options.

kofucii 08-23-2009 05:40 PM

--- for deletion ---

All times are GMT -5. The time now is 01:25 PM.