|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I am pretty new to shell scripting so this problem might be trivial, but I can't for the life of me figure it out or find any resources online that does what I want. Basically I am grepping from a large log file as I am only interested in certain entries. The code I am using is the following: MAILBODY=`grep -n "XX" ${LOGFILE}` SUBJECT="Logg informasjon" if [ "$MAILBODY" != '' ] ; then echo $MAILBODY | ${MAILPROGRAM} -s "${SUBJECT}" ${MOTTAKER} fi Just basically grepping the line with token XX then if data was found i send this via email. My problem is first of all, I do not want the token to be printed (not critical) secondly and most importantly I want each entry to be printed on separate lines as in adding a line break at the end of each result, because as it is it just tags all the lines after each other making it hopeless to use. Best Regards Mats Karstad |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2006-08-25, mats.karstad@gmail.com wrote:
> Hi, > > I am pretty new to shell scripting so this problem might be trivial, > but I can't for the life of me figure it out or find any resources > online that does what I want. > > Basically I am grepping from a large log file as I am only interested > in certain entries. > > The code I am using is the following: > > MAILBODY=`grep -n "XX" ${LOGFILE}` > SUBJECT="Logg informasjon" > > if [ "$MAILBODY" != '' ] ; then > > echo $MAILBODY | ${MAILPROGRAM} -s "${SUBJECT}" ${MOTTAKER} > fi > > Just basically grepping the line with token XX then if data was found i > send this via email. > > My problem is first of all, I do not want the token to be printed (not > critical) secondly and most importantly I want each entry to be printed > on separate lines as in adding a line break at the end of each result, > because as it is it just tags all the lines after each other making it > hopeless to use. Quote your variable: echo "$MAILBODY" | ${MAILPROGRAM} -s "${SUBJECT}" ${MOTTAKER} -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
That did it!
I love the simple solutions, thank you very much for the solution and the speedy reply :-) -Mats Chris F.A. Johnson wrote: > On 2006-08-25, mats.karstad@gmail.com wrote: > > Hi, > > > > I am pretty new to shell scripting so this problem might be trivial, > > but I can't for the life of me figure it out or find any resources > > online that does what I want. > > > > Basically I am grepping from a large log file as I am only interested > > in certain entries. > > > > The code I am using is the following: > > > > MAILBODY=`grep -n "XX" ${LOGFILE}` > > SUBJECT="Logg informasjon" > > > > if [ "$MAILBODY" != '' ] ; then > > > > echo $MAILBODY | ${MAILPROGRAM} -s "${SUBJECT}" ${MOTTAKER} > > fi > > > > Just basically grepping the line with token XX then if data was found i > > send this via email. > > > > My problem is first of all, I do not want the token to be printed (not > > critical) secondly and most importantly I want each entry to be printed > > on separate lines as in adding a line break at the end of each result, > > because as it is it just tags all the lines after each other making it > > hopeless to use. > > Quote your variable: > > echo "$MAILBODY" | ${MAILPROGRAM} -s "${SUBJECT}" ${MOTTAKER} > > > -- > Chris F.A. Johnson, author <http://cfaj.freeshell.org> > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) > ===== My code in this post, if any, assumes the POSIX locale > ===== and is released under the GNU General Public Licence |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 25 Aug 2006 00:52:22 -0700, mats.karstad@gmail.com
<mats.karstad@gmail.com> wrote: > > MAILBODY=`grep -n "XX" ${LOGFILE}` > SUBJECT="Logg informasjon" > > if [ "$MAILBODY" != '' ] ; then > > echo $MAILBODY | ${MAILPROGRAM} -s "${SUBJECT}" ${MOTTAKER} > fi > > Just basically grepping the line with token XX then if data was found i > send this via email. > > My problem is first of all, I do not want the token to be printed (not > critical) MAILBODY=`grep -n "XX" ${LOGFILE} | sed 's/XX//g'` MAILBODY=`awk '/XX/{gsub(/XX/,"") rint NR ":" $0}'`> secondly and most importantly I want each entry to be printed > on separate lines as in adding a line break at the end of each result, > because as it is it just tags all the lines after each other making it > hopeless to use. > echo "$MAILBODY" -- Microbiology Lab: Staph Only! |
|
![]() |
| Outils de la discussion | |
|
|