Obviously all of these sorts of things can be done with other tools too, but I wanted to illustrate that there are some fun ways to use more general purpose languages like awk or perl here. Maybe you want a line number counter and just the 6th field? How about this: tail -f /var/log/messages | \ grep > FPexamples.fta cut -c 2-11 prints out the gene names. Which will print the 6th through the last field of the output (fields are whitespace separated)Īnother similar idea is to use a perl one-liner: tail -f /var/log/messages | perl -ne "/myfilterword/ and print" tail -n +2 Thalas.txt shows from the second line to the end. You can expand on this by using the power of awk, for example: tail -f /var/log/messages | \Īwk '/myfilterword/ ' That works exactly the same as the example using grep. start tailing 100 lines from the end, and keep tailing, first exclude any lines with ACPI, then show lines with ata, ATA, or any mix of those. In addition, we applied buffer control via stdbuf. txt grep foo slightly modified to show the filename When its not piped, the filename is conveniently part of the output. i.e.: tail -100f /var/log/messages grep -V ACPI grep -i ata. In this article, we saw how grep can be used with continuous streams of data. Here's a couple other ideas, which while not as simple, may offer some interesting additional flexibility:įirst, you can filter with awk instead of grep: tail -f /var/log/messages | awk '/myfilterword/' and you can use multiple pipes and greps, and exclude things with grep -v, get case insensitivity with grep -i, etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |