Reputation: 1330
I want to grep the adb logcat and write the output to a text file. If I just do:
./adb logcat > std.txt
it writes the entire log to the text file. If I do:
./adb logcat | grep ABC
it prints all lines containing ABC to my terminal. But now I wish to search for ABC & write only these lines to a text file.
This:
./adb logcat | grep ABC > std.txt
doesn't work.
What's the correct command?
Upvotes: 41
Views: 71053
Reputation: 172
"To save LogCat to a text file open up a terminal window and type: adb logcat -d > logcat.txt"
Upvotes: 1
Reputation: 1866
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.
Upvotes: 5
Reputation: 1730
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
Upvotes: 6
Reputation: 2297
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?.
Upvotes: 58
Reputation: 61
Something like that maybe looking for all entries with word time, testapk1 and testapk2
adb logcat -v time testapk1 testapk2 *:S -d > adblogfilter.log
Upvotes: 1