grep the adb logcat & write the output to a text file
Edit: This seems to work
./adb logcat |grep --line-buffered ABC >a.txt
I can explain you what is happening heres. Hope someone can derive a solution from that.If you run the following command in terminal
cat |grep "ABC"
and start entering lines of text, you can see that grep immediately outputs any lines that contains.
cat somefile.txt | grep "ABC"
will print all lines that contains 'ABC' to the terminal, as expected.
But if you run
cat |grep ABC >a.txt
and start entering text on the terminal, you can see that the file is not written until you enter an EOF character (Ctrl+ D) and make cat terminate.
But using --line-buffered gives output in the expected way
cat |grep --line-buffered ABC >a.txt
Try adb logcat | grep ABC | tee out
This is working for me:
./adb logcat | grep ABC | dd of=/home/levex/dump.txt
Explanation: ./adb logcat
opens the logcat, and then it goes through a pipe to grep ABC
which filters the lines to those containing ABC
, and then again through a pipe to dd of=/home/levex/dump.txt
to finally print it to a file. of=xxx
parameter sets the output file.
I think there is a problem with grep buffering. You can try something like this:
./adb logcat | grep --line-buffered ABC > std.txt
It should be the same problem for chained grep.
EDIT: A similar question can be found here: Why no output is shown when using grep twice?.