Como executar o comando awk no Windows 7?

Como executar o comando awk no Windows 7?

Eu tenho o seguinte comando adb+ awkque funcionará bem no ambiente Linux[Ref.].

adb shell dumpsys package | awk -v RS='\n +Package' '/android\.permission\.CAMERA/{print $1}'

Mas preciso executar este comando no PC com Windows 7, que possuiGnuWin32 Gawkpacote instalado. Posso executar comandos awk da C:\Program Files (x86)\GnuWin32\binpasta e executar os comandos adb da C:\Program Files (x86)\Android\android-sdk\platform-toolspasta. Preciso executar o comando acima e obter a lista de pacotes que possuem as permissões CAMERA permitidas.

Definir variáveis ​​ambientais do Windows para AWKPATH e também em variáveis ​​PATH não funcionou. Então, apenas copiei o conteúdo da binpasta do GnuWin32 gawk e colei na platform-toolspasta. Mas quando executo no prompt de comando, recebo,

awk: +Package'
awk:         ^ invalid char ''' in expression

Como posso executar o comando acima no Windows? ou Qual é a expressão correta que posso executar?

Responder1

Tente substituir o 'por ". Para que o comando pareça,

adb shell dumpsys package | awk -v RS="\n +Package" "/android\.permission\.CAMERA/{print $1}"

Dê uma olhada também:Grep e Awk no Windows Caractere inválido em erro de expressão

Responder2

 It all depends on the version of GAWK you're running -- and how important it is to keep some old batch scripts working without modification.  (These days, if you're using AWK on Windows, it is almost certainly really GAWK.)  As duDE pointed out, changing the single quotes to double quotes will work -- but then you'll have to escape any double quotes inside the program.

 I just recently ran into this problem when I upgraded to GAWK 5.0.1 from v3.1.7, still running Windows 7.  (Yeah, I know...)  3.1.7 works just fine with the single quotes.  So, if you have some old scripts you want to keep without editing them or you just like the *established way* of running AWK, or just don't need whatever the newer versions bring, you might consider d/l'ing an older version.
 I don't know when it was changed, but someone dropped the ball in GAWK development somewhere between those two versions.  (I hate to say it, because I have been a pretty ardent M$ basher over the years and I have been a huge fan of public domain software and made a few contributions to the cause over the almost 30 years I've been programming and using other people's contributions.)  Truth is, we can't blame this one on Windows; it still works just fine with the old GAWK.  It's GAWK that introduced this problem.

informação relacionada