PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Formatting grep result.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Formatting grep result.

Réponse
 
LinkBack Outils de la discussion
Vieux 25/08/2006, 08h52   #1
mats.karstad@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Formatting grep result.

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

  Réponse avec citation
Vieux 25/08/2006, 09h05   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Formatting grep result.

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
  Réponse avec citation
Vieux 25/08/2006, 09h40   #3
Dodo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Formatting grep result.

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


  Réponse avec citation
Vieux 25/08/2006, 10h17   #4
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Formatting grep result.

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!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h46.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09493 seconds with 12 queries