grep: adb logcat &将输出写入文本文件。

时间:2022-05-16 02:46:56

I want to grep the adb logcat & write the output to a text file. If I just do

我要grep adb logcat,并将输出写入一个文本文件。如果我只做

./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.

它打印所有包含ABC的行到我的终端。但是现在我希望搜索ABC &只把这些行写在一个文本文件中。

./adb logcat | grep ABC > std.txt

doesn't work. Plz help.

是行不通的。请帮助。

7 个解决方案

#1


39  

I think there is a problem with grep buffering. You can try something like this:

我认为grep缓冲是有问题的。你可以试试这样的方法:

./adb logcat | grep --line-buffered ABC > std.txt

It should be the same problem for chained grep.

链接grep应该是同样的问题。

EDIT: A similar question can be found here: Why no output is shown when using grep twice?.

编辑:一个类似的问题可以在这里找到:为什么在使用grep两次时没有显示输出?

#2


4  

This is working for me:

这是为我工作:

./adb logcat | grep ABC | dd of=/home/levex/dump.txt

/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.

解释:。/adb logcat打开logcat,然后它通过一个管道到grep ABC,它将这些行过滤到包含ABC的行,然后再通过一个管道将其过滤到=/home/levex/dump。txt最终将它打印到一个文件中。=xxx参数设置输出文件。

#3


3  

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.

然后开始输入文本行,你可以看到grep立即输出任何包含的行。

 cat somefile.txt | grep "ABC" 

will print all lines that contains 'ABC' to the terminal, as expected.

按预期打印包含“ABC”到终端的所有行。

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.

然后在终端输入文本,您可以看到该文件直到输入EOF字符(Ctrl+ D)并使cat终止时才写入文件。

But using --line-buffered gives output in the expected way

但是,使用—行缓冲可以以预期的方式输出。

cat |grep --line-buffered  ABC >a.txt

#4


1  

Try this

试试这个

./adb logcat -s "ABC" > std.txt

#5


1  

Something like that maybe looking for all entries with word time, testapk1 and testapk2

类似这样的东西,可能需要用单词time, testapk1和testapk2来查找所有的条目。

adb logcat -v time testapk1 testapk2 *:S -d > adblogfilter.log 

#6


1  

Try adb logcat | grep ABC | tee out

试试adb logcat | grep ABC | tee。

#7


0  

Save LogCat To A Text File

将LogCat保存到文本文件。

"To save LogCat to a text file open up a terminal window and type: adb logcat -d > logcat.txt"

“将LogCat保存到一个文本文件中,打开终端窗口并输入:adb LogCat -d > LogCat .txt”。

#1


39  

I think there is a problem with grep buffering. You can try something like this:

我认为grep缓冲是有问题的。你可以试试这样的方法:

./adb logcat | grep --line-buffered ABC > std.txt

It should be the same problem for chained grep.

链接grep应该是同样的问题。

EDIT: A similar question can be found here: Why no output is shown when using grep twice?.

编辑:一个类似的问题可以在这里找到:为什么在使用grep两次时没有显示输出?

#2


4  

This is working for me:

这是为我工作:

./adb logcat | grep ABC | dd of=/home/levex/dump.txt

/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.

解释:。/adb logcat打开logcat,然后它通过一个管道到grep ABC,它将这些行过滤到包含ABC的行,然后再通过一个管道将其过滤到=/home/levex/dump。txt最终将它打印到一个文件中。=xxx参数设置输出文件。

#3


3  

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.

然后开始输入文本行,你可以看到grep立即输出任何包含的行。

 cat somefile.txt | grep "ABC" 

will print all lines that contains 'ABC' to the terminal, as expected.

按预期打印包含“ABC”到终端的所有行。

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.

然后在终端输入文本,您可以看到该文件直到输入EOF字符(Ctrl+ D)并使cat终止时才写入文件。

But using --line-buffered gives output in the expected way

但是,使用—行缓冲可以以预期的方式输出。

cat |grep --line-buffered  ABC >a.txt

#4


1  

Try this

试试这个

./adb logcat -s "ABC" > std.txt

#5


1  

Something like that maybe looking for all entries with word time, testapk1 and testapk2

类似这样的东西,可能需要用单词time, testapk1和testapk2来查找所有的条目。

adb logcat -v time testapk1 testapk2 *:S -d > adblogfilter.log 

#6


1  

Try adb logcat | grep ABC | tee out

试试adb logcat | grep ABC | tee。

#7


0  

Save LogCat To A Text File

将LogCat保存到文本文件。

"To save LogCat to a text file open up a terminal window and type: adb logcat -d > logcat.txt"

“将LogCat保存到一个文本文件中,打开终端窗口并输入:adb LogCat -d > LogCat .txt”。