Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


Search this Thread
Old 08-23-2009, 12:54 PM   #1
Registered: Apr 2006
Location: India
Posts: 473

Rep: Reputation: 33
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.
Old 08-23-2009, 01:00 PM   #2
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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.

Last edited by colucix; 08-23-2009 at 01:02 PM.
Old 08-23-2009, 02:36 PM   #3
Registered: Apr 2006
Location: India
Posts: 473

Original Poster
Rep: Reputation: 33
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.
Old 08-23-2009, 05:40 PM   #4
Registered: May 2007
Location: Bulgaria
Distribution: Slackware, SCO Unix
Posts: 62

Rep: Reputation: 20
--- for deletion ---

Last edited by kofucii; 08-23-2009 at 05:46 PM.


cgi, expression, form, regex, regular, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression matching , match "error string" but not "other error" jmcmillan Programming 3 07-07-2008 10:50 AM
Regular expression to extract "y" from "abc/x.y.z" rag84dec Linux - Newbie 1 05-29-2008 03:47 AM
Regular expression to match "^" then a number? PsychosisNode Linux - Newbie 1 01-14-2007 10:26 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 11:47 AM

All times are GMT -5. The time now is 02:28 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration