LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-24-2011, 03:27 PM   #1
protocol
LQ Newbie
 
Registered: May 2005
Posts: 17

Rep: Reputation: 0
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: http://www.linuxquestions.org/questi...e-line-909845/

Please assist.
 
Old 10-24-2011, 03:59 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
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?
 
Old 10-24-2011, 04:02 PM   #3
protocol
LQ Newbie
 
Registered: May 2005
Posts: 17

Original Poster
Rep: Reputation: 0
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.

Last edited by protocol; 10-24-2011 at 04:04 PM.
 
Old 10-24-2011, 04:15 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
so why not just do

tail -f /var/log/mail.log | grep to= | sed -nr 's/.*to=<([^>]*)>.*/\1/p'
 
Old 10-24-2011, 04:27 PM   #5
protocol
LQ Newbie
 
Registered: May 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie View Post
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..).

Panos
 
Old 10-24-2011, 04:36 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
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.
 
  


Reply

Tags
sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash; awk or sed output to variable: how keep newline at end of each output line porphyry5 Programming 3 06-10-2011 05:50 PM
How to assign a variable to the output value of a program BeyondSora Linux - Newbie 3 02-07-2011 12:46 AM
[SOLVED] Sed: assigning its output to a variable. stf92 Linux - Newbie 3 02-04-2011 12:38 AM
sed output -> variable problem figo Programming 13 05-31-2009 09:26 AM
bash script: how to assign an output (not the result) to a variable? Singing Banzo Programming 8 10-01-2006 06:29 PM


All times are GMT -5. The time now is 08:12 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration