|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I need script which should search for the "reason code" and it should send mail with its preceding line as well as the line below it.(first line before it and line after it) I used below script but it is printing the whole lines inside it, your help is appreciated: cd /app/usr/bin grep -i 'reason code' system.log > queue_line.txt ( cat queue_line.txt ) | mailx -s "reason code" hello@gmail.com system.log : ========= Feb 13 21:47:14 app20 please enter the valid input. system cannot understnd the queue you entered reason code 2085. from the default values. The Create MQ Channel (CRTMQMCHL) command creates a new MQ channel definition, specifying those attributes that are to be different |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
You can modify the Code:
grep code like this Code:
grep -C 1 'reason code' system.log | grep -v 'reason code' > queue_line.txt |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Try this Code:
count=`grep -n "reason code" $1 | awk '{print $1}' | cut -d":" -f 1`
prev_count=`expr $count - 1`
next_count=`expr $count + 1`
sed -n " $prev_count,$next_count p" $1 > queue_line.txt
cat queue_line.txt | mailx -s "reason code" hello@gmail.comscriptname filename Last edited by mirwasim; 02-20-2013 at 07:40 AM.. |
|
#4
|
||||
|
||||
|
http://www.unix.com/shell-programmin...using-sed.html Code:
sed -ne '/^reason code/{x;1!p;g;$!N;p;D;}' -e h x.dat | \
mailx -r "Reason_code_checker" -s "reason code" you@yourwork.com |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search a string and send the line containing it | rockingvj | Shell Programming and Scripting | 14 | 11-06-2012 10:22 AM |
| Script to send email after comparing the folder permissions to a certain permission & send email | nairshar | Shell Programming and Scripting | 2 | 12-07-2010 08:22 PM |
| Search for string and send mail | AnneAnne | Shell Programming and Scripting | 1 | 03-05-2009 05:21 AM |
| need help in finding a string and to send an email using shell script | ranga27 | Shell Programming and Scripting | 10 | 02-19-2008 04:54 PM |
| Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win) | Vetrivela | UNIX for Advanced & Expert Users | 2 | 02-15-2005 09:43 AM |
|
|