Assigning (tail) results to a variable
Hello all :-)
I hope you all doing great. I'm writing a script which in some part of it read some log file with the command ( tail ). I'd like to assign the result of tail | grip to a variable for some extra process. Here is an example of the command: Code:
tail /var/log/somefile -n20 | grep something Any help will be more than appreciated :) Thanks.. |
MYVAR=$(tail ... | grep ...)
|
Oh..
Great..!! The funny thing, is I really know that.. But I tried so many time, with so many ways.. And it was always failing.. After your answer, I got so sure that I was right, so I started digging some more deeper into the script. I discovered I was forgetting a part of a commented out command Un-commented. That was right before the tail command. SO, thanks you for your help :-) |
Depeding on what exactly you are doing, assigning text to a variable may not be the best idea. You can also send the results of any command to a file using redirection, e.g.:
tail /var/log/somefile -n20 | grep something >filename |
Hello pixellany,
Yes, in fact I know about redirecting the results to a file. The point is, I intended to assign the value to variable because the script will be taking actions depending on the results loaded at that variable. Let me illustrate the meaning using an example.. Let's assume we have an application running, and it's logging its status on a regular basis. Let's assume that application logs look like this: Code:
Oct 17 04:09: Processing Started.. So, an example will be like this: Code:
#!/bin/bash Kindly, Give me your opinion if you see or recommend something in such a case..!! :-) Thanks a lot. |
All times are GMT -5. The time now is 12:03 AM. |