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 07-04-2013, 03:49 PM   #1
andre3050
LQ Newbie
 
Registered: Jun 2013
Posts: 14

Rep: Reputation: Disabled
sed command to print expression plus entire line after


Hey guys

Using the following ced command with a lot of help from a couple of forum members which works great.
I cannot work out how to print the "said: xxx" and also include the rest of the line ie, description of the error, in bold below.

sed -rn 's/.*<([^>]*).*(said: 450*|said: 451*|said: 452*|said: 550*([- ]5\.1\.1)?).*/\1,\2/p' mail > out.txt

Eg, above ced urrently prints the 'Person@amailbox.com,said: 550' I'm guessing it's p ot 'p', which didn't work!

Jul 3 05:58:54 245ML postfix/smtp[15004]: 77FFC1665C0: to=<Person@amailbox.com>, relay=mail.amailbox.com[xxx.xxx.xxx.xxx]:25, delay=23, delays=0.82/0.13/21/0.26, dsn=5.0.0, status=bounced (host mail.amailbox.com[xxx.xxx.xxx.xxx] said: 550 <Person@amailbox.com>, Recipient unknown (in reply to RCPT TO command))

This is just one example error description.

Thanks and hope it makes sense!

Last edited by andre3050; 07-04-2013 at 03:51 PM.
 
Old 07-04-2013, 06:09 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you just want the whole line, you don't need sed, you could just use grep.
Here's sed
Code:
# just entire line
sed -rn 's/.*<([^>]*).*(said: 450*|said: 451*|said: 452*|said: 550*([- ]5\.1\.1)?).*/&/p'


# matches, followed by line 
sed -rn 's/.*<([^>]*).*(said: 450*|said: 451*|said: 452*|said: 550*([- ]5\.1\.1)?).*/\1,\2,&/p'
 
Old 07-05-2013, 09:42 AM   #3
andre3050
LQ Newbie
 
Registered: Jun 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi chrism01, thank you for tip.

Using the '# matches, followed by line'
Instead of printing, eg, Person@amailbox.com,said: said: 550 Person@amailbox.com, Recipient unknown (in reply to RCPT TO command)) Which would be perfect.

It actually prints:

Person@amailbox.com,said: 550,Jul 4 04:14:24 245ML postfix/smtp[15004]: 77FFC1665C0: to=<Person@amailbox.com>, relay=mail.amailbox.com[xxx.xxx.xxx.xxx]:25, delay=23, delays=0.82/0.13/21/0.26, dsn=5.0.0, status=bounced (host mail.amailbox.com[xxx.xxx.xxx.xxx] said: 550 <Person@amailbox.com>, Recipient unknown (in reply to RCPT TO command))


Seems to be adding another 'said:' and re positioning date and time
 
  


Reply



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
[SOLVED] sed gives :sed: -e expression #1, char 1: unknown command: `'' samasat Linux - Newbie 10 06-09-2012 05:31 PM
[SOLVED] sed edit the line above a regex expression corcodelagaze Programming 9 02-25-2012 08:52 AM
Embed command output in sed expression. AwesomeMachine Linux - Newbie 7 02-20-2010 02:48 PM
[SOLVED] sed or awk help - need to remove text on each line before a regular expression kmkocot Linux - Newbie 15 10-30-2009 03:20 AM
sed / awk command to print line number as column? johnpaulodonnell Linux - Newbie 2 01-22-2007 07:07 AM

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

All times are GMT -5. The time now is 05:49 AM.

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