Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read a text file line by line as a string 2

Status
Not open for further replies.

kimmers

Technical User
Aug 1, 2002
24
FI
Howdy,

I am trying to make a script which first greps 'failed' messages and puts them into file.

Then I need to read each line and send them i.e as a separate mailx message.
Here first tested with echo-command to see the output:

So how to read a line as a string so that it would handle each row as a entire line.
/tmp/logfile.log (looks like this)

" Login for user xxxx failed "
" Login for user yyyy was ok "
" Login for user zzzz failed "

============================

#!/bin/sh

grep failed /tmp/logfile.log > /tmp/failed.log

for i in `cat /tmp/failed.log`
do
echo $i
done

Output should look like this
" Login for user xxxx failed "
" Login for user zzzz failed "

but it looks like this
"
Login
for
user
xxxx
failed
"
"
Login
for
user
zzzz
failed
"

------------
So I wonder how to fix this prob,

#Kimmers





 
Hi Kimmers,
change line for i in `cat /tmp/failed.log`
to
while read i

and line done
to
done < /tmp/failed.log

Regards Boris
 
Hi kimmers,

Do it in this way :

grep failed /tmp/logfile.log > /tmp/failed.log

cat /tmp/failed.log | while read ln
do
echo $ln
done

Best Regards,
vivek
 
Thank You Boria and Vivek1712,

it worked as expected!!
And I appreciate your fast response :)

Take Care,

#Kimmers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top