Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,262 Members 50,131 Now Online
XDA Developers Android and Mobile Development Forum

[Article]Workaround for grep and Logcat, dmesg, and last_kmsg on Windows

Tip us?
 
wcypierre
Old
(Last edited by wcypierre; 1st January 2013 at 08:01 AM.)
#1  
Senior Member - OP
Thanks Meter 182
Posts: 432
Join Date: Apr 2012
Default [Article]Workaround for grep and Logcat, dmesg, and last_kmsg on Windows

In this article, I will explain some of the confusions that may occur whilst using grep in logcat, dmesg, kmsg and last_kmsg on different platforms,mainly between Unix(Linux based such as ubuntu, linux mint, fedora, BSD based such as netbsd, freebsd, and even Mac) and Windows(Windows XP, Windows Vista, Windows 7, Windows 8 and etc).

Requirements:
  1. Known about the existence of logcat, dmesg, kmsg, and last_kmsg and have tried logging it at least once
  2. Know some basic knowledge of batch/bash(cmd/terminal)
  3. Using Windows OS(The problem only lies on Windows, so if you're using Mac or Linux then you're fine)

Although this is a rather technical article, but I will make it as simple as possible for all of the users to understand

Sometimes, I will see some of the developers will issue similar to this:

Log Commands with Grep
Quote:
Logcat:
adb logcat | grep 'htc'

Dmesg:
adb shell dmesg | grep 'mp_decision'

last_kmsg:
adb shell cat /proc/last_kmsg | grep 'mp_decision'
So, the problem is?
The problem is that if you're using a Windows OS, Windows OS doesn't have grep installed, so your command would not run and you will see an error message like this:



Linux or Mac users will not have this problem as they have grep installed, so they are fine.

Workaround:
1. Install a Linux shell on Windows
2. Use a terminal app within the Android phone
3. Connect to the linux shell inside the Android Phone by using your computer
4. Use the built-in filters(for logcat ONLY)

Workaround #1
Quote:
You can simply click here and follow the simple steps to get a linux shell on your computer
Workaround #2
Quote:
You just need to download a terminal app from your phone and every command will work fine. You would need to omit the adb and adb shell keyword(refer below) in order for the command to work. A nice terminal app suggestion would be https://play.google.com/store/apps/d...roidterm&hl=en which you can simply download from Google Playstore
Workaround #3
Quote:
You can just type "adb shell" and press enter, then type your commands(omit all adb and adb shell keyword) and it will work just as like in workaround #2.
Example
Quote:
1. "adb shell" + enter
2. Choose the command that you wanted:

Logcat:
logcat | grep 'htc'

Dmesg:
dmesg | grep 'mp_decision'

last_kmsg:
cat /proc/last_kmsg | grep 'mp_decision'
Workaround #4
Quote:
This workaround is a workaround which only exists for logcat, because logcat have a filtering system that is built into it(makes us wonder why it is not built into dmesg and last_kmsg as well eh?).

For example, the grep command for the logcat above can be replaced by:

Quote:
adb logcat htc:V *:S
However, the downside is that you need to know the exact name of the app which is logged at the logcat in order to search for it while you can do a random keyword search with grep which helps a lot if you do not know what to look for.

For more information about the filtration, you can refer to http://developer.android.com/tools/d...gging-log.html
Conclusion:
Hopefully, after reading this article, you will know how to deal with grep when you're on Windows OS

Do drop me a question or two if you have something that you don't understand and stay tuned for more articles!
Want to make a logcat, dmesg, last_kmsg but don't know how?
AIOlog is your logging solution: http://forum.xda-developers.com/show...php?p=32994107


Looking for beta testers and translators, please contact me if you're interested
The Following 2 Users Say Thank You to wcypierre For This Useful Post: [ Click to Expand ]
 
nikufellow
Old
#2  
nikufellow's Avatar
Senior Member
Thanks Meter 808
Posts: 2,849
Join Date: May 2012
Location: simcity
Actually most of these are already known but neverthless nice guide

Ps: Limited to 8 thanks per day so will thank later !
 
wcypierre
Old
#3  
Senior Member - OP
Thanks Meter 182
Posts: 432
Join Date: Apr 2012
Quote:
Originally Posted by nikufellow View Post
Actually most of these are already known but neverthless nice guide

Ps: Limited to 8 thanks per day so will thank later !
I do agree that the last 3 solutions are common but there's still people who doesn't know about it.

But I think that there'll be quite some people who doesn't know about the first workaround though, as it is not covered in most tutorials(unless you're looking at a rom building tutorial on windows), or do you?

Sure thing and thanks in advance
Want to make a logcat, dmesg, last_kmsg but don't know how?
AIOlog is your logging solution: http://forum.xda-developers.com/show...php?p=32994107


Looking for beta testers and translators, please contact me if you're interested
 
ravike14
Old
#4  
ravike14's Avatar
Senior Member
Thanks Meter 1067
Posts: 1,294
Join Date: Feb 2013
Location: Colombo

 
DONATE TO ME
Found it when I needed the most, the 1st method.. Thanks, simple but a good article

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
My work :
[Kernel 3.4][Sense JB/AOSP JB] Ravike14-Kernel

 

HTC Amaze 4G related

Juopunutbear S-OFF
Super CID
bootloader unlocked
HBOOT : 1.93.2222
Latest Firmware
Powered by Faux v.31


STOCK GB ROM for those who screwed up without reading properly


hit the thanks buttons if i've helped you..need my assistance? mention me with your post


 
wcypierre
Old
#5  
Senior Member - OP
Thanks Meter 182
Posts: 432
Join Date: Apr 2012
Quote:
Originally Posted by ravike14 View Post
Found it when I needed the most, the 1st method.. Thanks, simple but a good article

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
You're welcome Glad to be of help even though this thread is already at least one year old
Want to make a logcat, dmesg, last_kmsg but don't know how?
AIOlog is your logging solution: http://forum.xda-developers.com/show...php?p=32994107


Looking for beta testers and translators, please contact me if you're interested
 
ravike14
Old
(Last edited by ravike14; 13th March 2014 at 08:54 PM.)
#6  
ravike14's Avatar
Senior Member
Thanks Meter 1067
Posts: 1,294
Join Date: Feb 2013
Location: Colombo

 
DONATE TO ME
Quote:
Originally Posted by wcypierre View Post
You're welcome Glad to be of help even though this thread is already at least one year old
i found it useful after year hehe....hey for some weird reason the method 1 and 3 fails when it comes to '' dmesg | grep 'xxx' > dmesg.txt '' commad :/ the text comes empty even tho the grep related logs are there in the normal dmesg when i try method 1 using [Msysgit]..when i try the 3rd method it just say read only file system and stops if i choose the output as a .txt file..when i enter 'dmesg | grep 'xxx' without '.txt' it do nothing :/
My work :
[Kernel 3.4][Sense JB/AOSP JB] Ravike14-Kernel

 

HTC Amaze 4G related

Juopunutbear S-OFF
Super CID
bootloader unlocked
HBOOT : 1.93.2222
Latest Firmware
Powered by Faux v.31


STOCK GB ROM for those who screwed up without reading properly


hit the thanks buttons if i've helped you..need my assistance? mention me with your post


 
wcypierre
Old
#7  
Senior Member - OP
Thanks Meter 182
Posts: 432
Join Date: Apr 2012
Quote:
Originally Posted by ravike14 View Post
i found it useful after year hehe....hey for some weird reason the method 1 and 3 fails when it comes to '' dmesg | grep 'xxx' > dmesg.txt '' commad :/ the text comes empty even tho the grep related logs are there in the normal dmesg when i try method 1 using [Msysgit]..when i try the 3rd method it just say read only file system and stops if i choose the output as a .txt file..when i enter 'dmesg | grep 'xxx' without '.txt' it do nothing :/
For the 1st method, there won't be any output as it is redirected to the file 'dmesg.txt'. Or you're indicating that the dmesg.txt file is empty?
For the 3rd one, are you running it on a rooted phone or stock bootloader?

Last but not least, can you give me an example of the command that you had tried for the 1st and 3rd method and a snippet of the dmesg.txt so that I can look into your problem?
Want to make a logcat, dmesg, last_kmsg but don't know how?
AIOlog is your logging solution: http://forum.xda-developers.com/show...php?p=32994107


Looking for beta testers and translators, please contact me if you're interested
 
ravike14
Old
#8  
ravike14's Avatar
Senior Member
Thanks Meter 1067
Posts: 1,294
Join Date: Feb 2013
Location: Colombo

 
DONATE TO ME
Quote:
Originally Posted by wcypierre View Post
For the 1st method, there won't be any output as it is redirected to the file 'dmesg.txt'. Or you're indicating that the dmesg.txt file is empty?
For the 3rd one, are you running it on a rooted phone or stock bootloader?

Last but not least, can you give me an example of the command that you had tried for the 1st and 3rd method and a snippet of the dmesg.txt so that I can look into your problem?
The dmesg.txt is empty, not even adb daemon text is there.. And yea I'm rooted and s-off.... I tried

For 1st method

adb shell dmesg | grep 'wl127xx' > dmesg.txt

For 3rd i tried

dmesg grep 'wl127xx'

And

dmesg grep 'wl127xx' > dmesg.txt

Tried the 3rd method even in Linux shell still a no go the txt is empty it just creates it and that's it.. When I execute the command without 'grep' I get the dmesg logs correctly.. But I really want the grep part lol..

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
My work :
[Kernel 3.4][Sense JB/AOSP JB] Ravike14-Kernel

 

HTC Amaze 4G related

Juopunutbear S-OFF
Super CID
bootloader unlocked
HBOOT : 1.93.2222
Latest Firmware
Powered by Faux v.31


STOCK GB ROM for those who screwed up without reading properly


hit the thanks buttons if i've helped you..need my assistance? mention me with your post


 
wcypierre
Old
(Last edited by wcypierre; 13th March 2014 at 10:56 PM.)
#9  
Senior Member - OP
Thanks Meter 182
Posts: 432
Join Date: Apr 2012
Quote:
Originally Posted by ravike14 View Post
The dmesg.txt is empty, not even adb daemon text is there.. And yea I'm rooted and s-off.... I tried

For 1st method

adb shell dmesg | grep 'wl127xx' > dmesg.txt

For 3rd i tried

dmesg grep 'wl127xx'

And

dmesg grep 'wl127xx' > dmesg.txt

Tried the 3rd method even in Linux shell still a no go the txt is empty it just creates it and that's it.. When I execute the command without 'grep' I get the dmesg logs correctly.. But I really want the grep part lol..

Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
can you copy the text snippet of the dmesg that contains the 'wl127xx' text then? A screenshot or the actual text would do
Want to make a logcat, dmesg, last_kmsg but don't know how?
AIOlog is your logging solution: http://forum.xda-developers.com/show...php?p=32994107


Looking for beta testers and translators, please contact me if you're interested
 
ravike14
Old
#10  
ravike14's Avatar
Senior Member
Thanks Meter 1067
Posts: 1,294
Join Date: Feb 2013
Location: Colombo

 
DONATE TO ME
Quote:
Originally Posted by wcypierre View Post
can you copy the text snippet of the dmesg that contains the 'wl127xx' text then? A screenshot or the actual text would do
if you mean the normal dmesg text,
Attached Files
File Type: txt dmesg.txt - [Click for QR Code] (132.8 KB, 4 views)
My work :
[Kernel 3.4][Sense JB/AOSP JB] Ravike14-Kernel

 

HTC Amaze 4G related

Juopunutbear S-OFF
Super CID
bootloader unlocked
HBOOT : 1.93.2222
Latest Firmware
Powered by Faux v.31


STOCK GB ROM for those who screwed up without reading properly


hit the thanks buttons if i've helped you..need my assistance? mention me with your post



Tags
dmesg, grep, kmsg, logcat, workaround
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes