LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-23-2009, 11:54 AM   #1
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
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:
Code:
$body =~ s/\n\.\n/\n\. \n/gm
Any help will be appreciated. Thank you.
 
Old 08-23-2009, 12:00 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can try the regexp notation for the beginning and the end of the line, that is ^ and $ respectively:
Code:
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 12:02 PM.
 
Old 08-23-2009, 01:36 PM   #3
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Original Poster
Rep: Reputation: 34
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, 04:40 PM   #4
kofucii
Member
 
Registered: May 2007
Location: Bulgaria
Distribution: Slackware, SCO Unix
Posts: 62

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

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


Reply

Tags
cgi, expression, form, regex, regular, sendmail



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 09:50 AM
Regular expression to extract "y" from "abc/x.y.z" rag84dec Linux - Newbie 1 05-29-2008 02:47 AM
Regular expression to match "^" then a number? PsychosisNode Linux - Newbie 1 01-14-2007 09:26 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:13 PM.

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