Grep out ONLY subject from maillog


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep out ONLY subject from maillog
# 1  
Old 11-15-2013
Grep out ONLY subject from maillog

I have the following entries in maillog. I need to grep out only the subject part from the following entries. Maillog contain following entries.

Code:
2013-11-14 03:30:02 [441847] 1Vgnd4-001qwZ-36 <= user@domain.com U=user P=local S=9797  id=cd3732bbd0fbda5cb16384bb7d5b465d@localhost.localdomain T="Subject Subject  Subject" from <user@domain.com> for  anothermail@newdomain.com

After applying the sed/awk, we should get result as follows.
Code:
Subject Subject  Subject

To summarize, the pattern, after T= should be printed.

Eg:
T="sub sub sub"
Should print
sub sub sub
# 2  
Old 11-15-2013
try:

Code:
sed -n 's/.*T="\([^"]*\)".*/\1/p' infile

or
Code:
awk -F\" '/T=/{print $2}' infile

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 11-15-2013
Code:
echo '2013-11-14 03:30:02 [441847] 1Vgnd4-001qwZ-36 <= user@domain.com U=user P=local S=9797  
id=cd3732bbd0fbda5cb16384bb7d5b465d@localhost.localdomain T="Subject Subject  Subject" 
from <user@domain.com> for  anothermail@newdomain.com' | perl -nle 'print $1 if (/T="(.+?)"/)'

This User Gave Thanks to pravin27 For This Post:
# 4  
Old 11-15-2013
Another awk
Code:
awk '/T=/ {f=NR} f&&NR-1==f' RS=\" file
Subject Subject  Subject

or this:
Code:
awk '/T=/ {getline;print}' RS=\" file
Subject Subject  Subject

@Chubler_XL
This awk -F\" '/T=/{print $2}' infile is not very robust.
It just print second field (using " as FS) if the line contain T=. So if other filed has quotes this will fail.

Last edited by Jotne; 11-15-2013 at 02:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. Shell Programming and Scripting

Filter maillog

Hi, I need to take them all fields SendTo and ip address from a file maillog First I look at all emails from containing the empty field. # zcat /var/log/mail/maillog-20140331.server1.gz | grep "from=<>" | awk '{print $6}' > 1.txt output: Mar 30 23:31:24 servidor1 postfix/smtpd:... (2 Replies)
Discussion started by: Jomeaide
2 Replies

3. UNIX for Dummies Questions & Answers

How to grep a string and add to subject line of a mail?

I am running a mailx command as follows in Linux: mailx -s "Elapsed Time: " ora_dbas < $RUNDIR/sql_timings.out I am trying to parse the file "sla_local_sql_timings.out" for the word Elapsed Time: and get the time from that file stored in a variable and display that variable in the subject... (4 Replies)
Discussion started by: vrkcamry
4 Replies

4. Shell Programming and Scripting

Grep the last line and put on mail subject

I have mail: cat /home/oracle/scripts/dbsizedaily.txt | mail -s "$TODAY: PROD DB Size" $RECIPIENTS I like to get and put USED_GB and %USED of the very last row from /home/oracle/scripts/dbsizedaily.txt. /home/oracle/scripts/dbsizedaily.txt has : DATE TIME TOTAL_GB USED_GB ... (6 Replies)
Discussion started by: Daniel Gate
6 Replies

5. Solaris

Flood Messages in maillog

Hi All, I am getting large number of messages in below file /www/wls8/logs/HOSTS/tswebd01-zd01/maillog/maillog In past 24 hours, it has been increased by near to 1 GB. Can somebody help in finding, from where these messages are being generated and how to I stop them ? Same kind of messages... (11 Replies)
Discussion started by: solaris_1977
11 Replies

6. UNIX for Advanced & Expert Users

/var/log/maillog isn't updating. Postfix related

can someone please help me figure how i can get maillog to start updating again? it just all of a sudden stopped. and postfix isn't writing to it anymore. I'm running a Ubuntu box 8.04 thanks (2 Replies)
Discussion started by: SkySmart
2 Replies

7. Gentoo

inserting grep -c value into an email subject

I am profoundly new to *nix, but had a project dropped in my lap that has sparked an interest, leading me here. I was tasked with daily sending one of our customers a listing of all the spam our filter blocked that was heading for them. Between Google and I; I discovered the Server is running... (3 Replies)
Discussion started by: GrendelPrime
3 Replies

8. UNIX for Advanced & Expert Users

maillog errrors

Watching my maillog this morning i have discovered some errors but I cant track down whats causing them. Jun 16 11:04:12 ws096 sendmail: m5GExW7e006613: Milter (spamass-milter): timeout before data read Jun 16 11:04:12 ws096 sendmail: m5GExW7e006613: Milter (spamass-milter): to error state Jun... (3 Replies)
Discussion started by: mcraul
3 Replies

9. UNIX for Advanced & Expert Users

maillog extract

Hi all, below are some text extracted from maillog. I have a cronjob running at 1720 daily and it will send mails to me. it was working fine on the 27 Sept.Sep 27 17:20:01 venus sendmail: k8R9K0OR032710: from=user1, size=580, class=0, nrcpts=1, msgid=<200609270920.k8R9K0OR032710@venus.domain.com>,... (1 Reply)
Discussion started by: new2ss
1 Replies

10. Shell Programming and Scripting

maillog - Error Message

dear expert Im using shell script to send mail from unix server. My script like below: #! /bin/sh -f # Set necessary variables #export PATH #PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/contrib/bin PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/contrib/bin:$PATH; export PATH... (0 Replies)
Discussion started by: unknown2205
0 Replies
Login or Register to Ask a Question