Windows 7 で awk コマンドを実行するにはどうすればいいですか?

Windows 7 で awk コマンドを実行するにはどうすればいいですか?

Linux環境で問題なく動作する以下のadb+コマンドがありますawk[参照]

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

しかし、私はWindows 7 PCでこのコマンドを実行する必要があります。GnuWin32 ゴークパッケージがインストールされています。フォルダーから awk コマンドを実行しC:\Program Files (x86)\GnuWin32\bin、フォルダーから adb コマンドを実行できますC:\Program Files (x86)\Android\android-sdk\platform-tools。上記のコマンドを実行して、CAMERA 権限が許可されているパッケージのリストを取得する必要があります。

AWKPATH および PATH 変数の Windows 環境変数の設定は機能しませんでした。そこで、GnuWin32 gawk のbinフォルダの内容をコピーして、フォルダに貼り付けましたplatform-tools。しかし、コマンド プロンプトで実行すると、

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

上記のコマンドを Windows で実行するにはどうすればよいですか? または、実行できる正しい式は何ですか?

答え1

'を に置き換えてみてください"。コマンドは次のようになります。

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

こちらもご覧ください:Windows の Grep と Awk で式に無効な文字があるというエラーが発生する

答え2

 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.

関連情報