2024-07-06
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
existadb shell logcat
Combine in commandgrep
To filter logs, if you want to match two substrings at the same time, you can use a pipe (|
) Put twogrep
Commands are linked together, or usinggrep
of-E
(oregrep
, which is equivalent to-E
) option to support extended regular expressions, so you can use logical OR (|
) to match multiple patterns.
grep
OrderIn this method, the firstgrep
The command filters out the lines containing the first substring, then the secondgrep
The command then filters out the lines containing the second substring from these lines.
bash复制代码
adb shell logcat -b all | grep '子串1' | grep '子串2' |
grep
of-E
OptionsThis approach is more concise because it allows you togrep
Multiple modes can be specified in the command at the same time.
bash复制代码
adb shell logcat -b all | grep -E '子串1|子串2' |
But please note that the above command will actually match lines containing either "substring 1" or "substring 2", not lines containing both. If you want to match both substrings at the same time, you should write:
bash复制代码
adb shell logcat -b all | grep '子串1' | grep '子串2' |
Or usegrep
of-z
(Note: This is not a standardgrep
but some versions ofgrep
orzgrep
Support) orawk
etc. to handle multi-line matching (which is often more complex and not necessary for simple scenarios).
However, if you really need to match two substrings in a regular expression (and the two substrings can appear anywhere on the same line), you can use the analogy of logical AND (although you are actually using logical OR).|
, but by ensuring that both substrings appear in the pattern):
bash复制代码
adb shell logcat -b all | grep -E '子串1.*子串2|子串2.*子串1' |
This command will match the occurrence of "substring 1" first and "substring 2" second, or "substring 2" first and "substring 1" second in the same line. Note that this pattern does not strictly require the two substrings to be adjacent, and there can be any number of characters between them. If you need them to be adjacent, you can remove the middle.*
。