LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2008, 09:36 AM   #1
romainp
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Rep: Reputation: 0
Grep result in a loop and linefeed issue


Hi,
I try to grep a file (syslog file) and display the result using a loop. Unfortunatly, there is an issue with the code below because of the libefeed/carriage return.
I try to find a way to have each grep result into a single line so I can use it into a the loop:



Code:
for res in $(grep 'pam_unix' $LOG_DIR/$server--$YEAR-$MONTH_D-$DAY_D_ZERO.log | grep 'session opened' | grep -v 'closed'); do

                echo "res : $res"

done
Right now, each 'res' results is a single word from the grep result... I can't find a way to catch the end of line and put the the line into the 'res' variable.

Any help will be greatly appreciated!
Thanks
 
Old 06-13-2008, 10:05 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Code:
grep 'pam_unix' $LOG_DIR/$server--$YEAR-$MONTH_D-$DAY_D_ZERO.log | grep 'session opened' | grep -v 'closed' |
while read res ; do 
echo "res : $res"
done
 
Old 06-13-2008, 10:11 AM   #3
romainp
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Perfect! it works!
thanks for taking the time to help me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using find and grep - how to exclude a result ? graziano1968 Linux - General 13 12-04-2010 10:02 PM
showing grep result without the whole line Dr_Death_UAE Linux - General 12 09-07-2006 06:12 AM
ps -ef | grep iptables gives no result ? markraem Linux - Networking 1 07-07-2004 05:28 AM
how to grep within a script, and test result? bobbyr Programming 4 01-13-2004 12:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration