1/19/2024 0 Comments Grep tail![]() ![]() Therefore, we cannot do tail -Fq a b and must instead use separate processes for each file. This is just the way it is and tail currently provides no way to changes this. There's actually two problems that this handles:įirst, tail -F will consume and output the bytes in the files as it sees them, without waiting for the end of line. To turn it into a one-liner, get rid of the line breaks and put semicolons ( ) at the end of lines that don't end with an ampersand ( &). The subshell ( ) may not be required if this is going into a shell script. Putting it together, a multi-line version is: ( Regarding grep -F / fgrep versus normal regex grep, using fixed string grep is slightly faster than something like grep ^ -line-buffered for the same purpose. grep -F here can be replaced with fgrep for short. It's very similar to the question's second example but the command to use is grep -F '' -line-buffered. ![]() Here's a solution that works without installing extra programs such as multitail. ![]() (Also, is there a better way of doing what grep -F '' does here?) I think it has the same restrictions discussed in this question: Is echo atomic when writing single lines However, I'm not sure how durable this is. $ (trap 'kill 0' EXIT tail -F a | grep -F '' & tail -F b | grep -F '' & wait) Use separate instances and use grep to buffer each line. However, I think this just moves the problem from tail to the pipe buffer and the problem isn't resolved. Instead of using a single tail -Fq, I tried separate tail instances for each file: $ (trap 'kill 0' EXIT tail -F a & tail -F b & wait) How do I output these lines without them getting mixed up? In reality, something like abA\nB\n is produced. tail -F) can produce broken lines: For instance, lines ABC\n and XYZ\n from two logs can get mixed up and become ABXYZ\nC\n. However, doing so without much thought (e.g. I want to follow multiple log files and output the incoming lines to a single pipe. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |