1
I have the following adb
+ awk
command which will work fine in Linux environment [Ref].
adb shell dumpsys package | awk -v RS='\n +Package' '/android\.permission\.CAMERA/{print $1}'
But I need to run this command in Windows 7 PC which has GnuWin32 Gawk package installed. I can run awk commands from the C:\Program Files (x86)\GnuWin32\bin
folder and run the adb commands from the C:\Program Files (x86)\Android\android-sdk\platform-tools
folder. I need to run the above command and get the list of packages that has the CAMERA permissions allowed.
Setting Windows Environmental Variables for AWKPATH and also in PATH variables didn't work. So I just copied the contents of GnuWin32 gawk's bin
folder and pasted in the platform-tools
folder. But when I run in command prompt I get,
awk: +Package'
awk: ^ invalid char ''' in expression
How can I run the above command in Windows? or What is the correct expression that I can run?
Try to replace the ' with " : http://stackoverflow.com/questions/4852270/grep-and-awk-in-windows-invalid-char-in-expression-error
– duDE – 2015-09-15T11:17:57.583Really you should have tried a bit of troubleshooting. e.g. Try just using Gawk for a simple case and see if you get that error..then it may be clearer to you what the problem is – barlop – 2015-09-15T11:19:52.603
@barlop I'm new to gawk and simple examples works fine. I only had problems with case including the
'
. But that is solved now according to the user duDE mentioned. – Lucky – 2015-09-15T11:25:49.7171@duDE that solved the issue. Thanks. Could you post that as an answer. – Lucky – 2015-09-15T11:26:10.700
1@Lucky The point is that troubleshooting involves looking at what doesn't work and looking at what works and changing each to pinpoint the error. e.g. trying to change the one that doesn't work into something simpler. So you could have tried simplifying the left hand side to echo asdf, and you'd see you still get the error, then you could have done
echo asdf | awk -v RS='b' '{print $1}'
and got that error. You still get the error but it's much easier for you or anybody to diagnose.. nothing to do with adb or android for example, it rules that out. – barlop – 2015-09-15T12:01:45.500@barlop Okay, thanks for the advice. As I mentioned already I'm just new to using gawk commands as I'm a Windows user and I didn't knew it had nothing to do with adb command. In the end, it was just a simple mistake. ;) – Lucky – 2015-09-15T12:05:39.563
@Lucky though notice that the troubleshooting that I suggested doesn't involve knowing anything about what awk or gawk is doing – barlop – 2015-09-15T12:07:23.377