print multiple lines using the grep command.

Hi All,
Please find my piece of code below. I am trying to grep the word SUCCESS from $LOGFILE and storing in the grepvar variable. And i am placing that variable in a file. Now if i open the file, i can see the four lines but not in seperate four line s but in a paragraph. If am mailing that log file to my mail its displaying as a paragraph.
Now i need that four lines a four line not as a paragraph.

export grepvar=`grep -i "SUCCESS" ${LOGFILE}` 
echo $grepvar >> ${MAILLOG}

Please help me in this.

Thanks in advance.
Raju

Quote the variable:

export grepvar=`grep -i "SUCCESS" ${LOGFILE}` 
echo "$grepvar" >> ${MAILLOG}

Please see RESULT STORED IN THE variable.
Synch happend before shutdown and the synch is SUCCESS for Affinity Database Startup happend after the split and the split is in SUCCESS State

I hope somebody can follow this, but it's not me...:eek:

What has this to do with your first question?

I supose tha you need the variable, because if not the case the more easy is

grep -i "SUCCESS" ${LOGFILE} >> ${MAILLOG}

well if yo need the var then this code put in the var an in the file

export grepvar=`grep -i "SUCCESS" ${LOGFILE}| tee -a  ${MAILLOG}` 

Hi The above code dint work.

Please see my output below. The SUCCESS word has come twice in the log file. but when i am trying to mail that logfile, its coming in one line.
How to display it in two lines.

Checking the validity for Affinity daily backup on Wed Aug 26 07:43:25 EDT 2009
-------------------------------------------------------------------------------
SUCCESS- with the start time of the Paris daily backup box SUCCESS- with the Paris split date

What Operating System are you using?
How are you sending the mail?
How are you reading the mail?

If you are reading the mail with Microsoft Office Outlook, look at the following setting in that program:
Tools / Options / Email Options / "Remove extra line breaks in plain text messages".
If that option is set, uncheck the box.

[aaaa@bbbb] $ cat a.txt
ddddddddddddddddd ffffffffffffffffffffffffff dddddddddddddddddddddddddddd ssssssssssssssssssssssssssss ggggggggggggggggggggggggg dddddddddddddddddddddd fffffffffffffffffffffffff ddddddddddddddddddddddddddd sssssssssssssssssssssssss fffffffffffffffffffffffff ssssssssssssssssssssssssssss ffffffffffffffffffff vvvvvvvvvvvvvvvvvvvvvvvvvvvv xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ssssssssssssssssssssssssssssssssss dddddddddddddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee ccccccccccccccccccccccc

b=`grep f a.txt`
start_pos=0
increment=100
counter=1
while(true)
do
print_line=`echo $b | cut -c$start_pos-$increment`
start_pos=`expr $start_pos + 100`
increment=`expr $start_pos + 100`
if [ -z "$print_line" ]
then
break
fi
echo $counter " " $print_line
counter=`expr $counter + 1`
done

O/p:

1 ddddddddddddddddd ffffffffffffffffffffffffff dddddddddddddddddddddddddddd ssssssssssssssssssssssssss
2 sss ggggggggggggggggggggggggg dddddddddddddddddddddd fffffffffffffffffffffffff dddddddddddddddddddddd
3 dddddd sssssssssssssssssssssssss fffffffffffffffffffffffff ssssssssssssssssssssssssssss fffffffffffff
4 ffffffff vvvvvvvvvvvvvvvvvvvvvvvvvvvv xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
5 b ssssssssssssssssssssssssssssssssss dddddddddddddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeee
6 ee ccccccccccccccccccccccc

---------- Post updated at 07:27 AM ---------- Previous update was at 07:21 AM ----------

If you want complete words, you can use the field separator:

b=`grep f a.txt`
start_pos=1
increment=4
counter=1
while(true)
do
print_line=`echo $b | cut -d " " -f$start_pos-$increment`
start_pos=`expr $start_pos + 4`
increment=`expr $start_pos + 4`
if [ -z "$print_line" ]
then
break
fi
echo $counter " " $print_line
counter=`expr $counter + 1`
done

The code work perfect in hp-ux with sh.
I'm not sure if i undertand you, if you put and example think is better.
This is what i'm think is you problem:

Script started on Wed Aug 26 15:23:51 2009
$more file
Koption1 Value1
option2 Value2
option3 Value3
option4 Value4
$grep option file
option1 Value1
option2 Value2
option3 Value3
option4 Value4
$buffer=`grep option file`
$echo $buffer
option1 Value1 option2 Value2 option3 Value3 option4 Value4
$ls new_file
new_file no encontrado
$buffer2=`grep option file|tee -a new_file`
$echo $buffer2
option1 Value1 option2 Value2 option3 Value3 option4 Value4
$more new_file
option1 Value1
option2 Value2
option3 Value3
option4 Value4

script done on Wed Aug 26 15:25:50 2009

the problem is the echo of variable is in one line and you want the 4lines?