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 Invalid Char in Expression Error의 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.

관련 정보