-   Linux - General (
-   -   Can not assign variable to output of sed (

protocol 10-24-2011 03:27 PM

Can not assign variable to output of sed
Hello all

Why is the following line not printing anything on the screen:

tail -f /var/log/mail.log | var=`sed -nr 's/.*to=<([^>]*)>.*/\1/p'` echo $var;

Note: This thread related to this one:

Please assist.

acid_kewpie 10-24-2011 03:59 PM

it just kinda makes no sense at all, in many ways, I'm afraid. what do you expect it to do? the echo command is being tagged onto the end of the assignment execution, you're following the tail, that command will never finish... drop the idea of assigning the sed output to anything, i'm sure your output can easily be made to fall out the end, do you now just want a grep after it maybe?

protocol 10-24-2011 04:02 PM

Hello Chris.

What i want, is to take sed's output (an email address) and "post" that address to an external script that will -in turn- insert that email address to a database. Sorry for my poor bash skills, i just feel certain that it can be done somehow. No?

Regards, Panos.

acid_kewpie 10-24-2011 04:15 PM

so why not just do

tail -f /var/log/mail.log | grep to= | sed -nr 's/.*to=<([^>]*)>.*/\1/p'

protocol 10-24-2011 04:27 PM


Originally Posted by acid_kewpie (Post 4506981)
so why not just do

tail -f /var/log/mail.log | grep to= | sed -nr 's/.*to=<([^>]*)>.*/\1/p'

This also prints email addresses on the screen (quite natural, since you made it ..:)) and still leaves me wondering how would i go about with "posting" the result of grep to an external script. Again, sorry for my poor knowledge of bash scripting (i am getting better by the minute, hanging out with you people..).


acid_kewpie 10-24-2011 04:36 PM

well you'd probably just pipe it again onto yet another command. Note again though, as you're tail -f'ing this, the command will never complete, so you need to work out how to deal with that.

All times are GMT -5. The time now is 07:43 PM.