Afficher un message
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
 
Page generated in 0,06123 seconds with 9 queries