![]() |
Unix Help - Tail | Grep
I'm trying to grep a tail -f out to a file.
But it doesn't seem to be working. I am doing: tail -f file | grep 'term' > file.txt No output to file. Anyone see what is wrong? Any ideas how to do this? |
That's correct, and I just tried and it works with me.
Is the file created but empty? |
Yes, that is what is happening.
|
Anyone else help? I'm stuck.
I've scripted something up in perl but when the file gets truncated the perl script stops outputting to file. |
looks fine to me, post your code
|
PHP Code:
The grep option works without sending to file AND sending to file works without the grep there. It seems that soemthing is messed up. |
Bump?
|
hrm, perhaps you might try using 2&>/path/to/file
edit I havent touched perl in ages but what you've got there looks fine to me. |
im sure im probably mistaken but shouldn't
>> /home/me/outputfile be > /home/me/outputfile or at least have a statement to use concatonate or append depending on weather or not the file exists. *shrug* |
Hrmm, well depending on what I want to do, >> is just because I don't want to kill what is there now. Appending is much better for me.
I don't even need to use that script, I just need to tail -f a logfile and grep the output to another file. That's it. I'm lost. |
A Final Bump
|
hate to ask a stupid question, but is there anything in the file your trying to tail?
|
It's the way that grep dumps the data pipe into standard out.
Give who | sort >> user.txt a try and I bet it works for you. You're going to need to write a quick hack in perl to open a file and then dump all standard input to it. Stick that in place of the >> yourfile in your pipe chain. tail | grep | hack.pl ...or spend all day pulling your hair out searching for an answer you probably won't find. :) |
output buffering .. need to reach a certain amount of lines before the last pipe gets it.
|
and ...
tail -f file | awk '/term/ { print; fflush() }' > file.txt .. solves it. |
Quote:
Thanks a BUNCH, I really appreciate it. Thanks to everyone who helped in this thread, I knew there were some fellow nix dorks lurking around here and I wasn't alone. J |
All times are GMT -7. The time now is 07:39 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123