如何在 Windows 中运行 awk 命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21927944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:23:59  来源:igfitidea点击:

How to run an awk commands in Windows?

windowsawk

提问by David Ball

I have downloaded gawk from here, but I can't seem to figure out how to use it. I am simply trying to run a command, not to write one.

我已经从这里下载了 gawk ,但我似乎无法弄清楚如何使用它。我只是想运行一个命令,而不是写一个。

采纳答案by Mark Setchell

If you want to avoid including the full path to awk, you need to update your PATH variable to include the path to the directory where awk is located, then you can just type

如果要避免包含 awk 的完整路径,则需要更新 PATH 变量以包含 awk 所在目录的路径,然后只需键入

awk

to run your programs.

运行你的程序。

Go to Control Panel->System->Advanced and set your PATH environment variable to include "C:\Program Files (x86)\GnuWin32\bin" at the end (separated by a semi-colon) from previous entry. enter image description here

转到“控制面板”->“系统”->“高级”并将您的 PATH 环境变量设置为在上一个条目的末尾(用分号分隔)包含“C:\Program Files (x86)\GnuWin32\bin”。 在此处输入图片说明

回答by thebjorn

Quoting is an issue if you're running awk from the command line. You'll sometimes need to use \, e.g. to quote ", but most of the time you'll use ^:

如果您从命令行运行 awk,则引用是一个问题。您有时需要使用\,例如引用",但大多数时候您会使用^

w:\srv>dir | grep ".txt" | awk "{ printf(\"echo %s@%s ^> %s.tstamp^\n\", , , ); }"
echo 2014-09-07@22:21 > requirements-dev.txt.tstamp
echo 2014-11-28@18:14 > syncspec.txt.tstamp

回答by Mithrandir

You can download and run the setup file. This should install your AWKin "C:\Program Files (x86)\GnuWin32". You can run the awkor gawkcommand from the binfolder or add the folder ``C:\Program Files (x86)\GnuWin32\binto yourPATH`.

您可以下载并运行安装文件。这应该安装AWK在“ C:\Program Files (x86)\GnuWin32”中。您可以从文件夹运行awkgawk命令bin或添加文件夹``C:\Program Files (x86)\GnuWin32\bin to yourPATH`。

enter image description here

在此处输入图片说明

回答by Bams

Actually, I do like mark instruction but little differently. I've added C:\Program Files (x86)\GnuWin32\bin\to the Path variable, and try to run it with type awk using cmd.

实际上,我确实喜欢标记指令,但几乎没有什么不同。我已添加C:\Program Files (x86)\GnuWin32\bin\到 Path 变量,并尝试使用 cmd 以 awk 类型运行它。

Hope it works.

希望它有效。

回答by Jotne

Go to command windows (cmd) then type:

转到命令窗口(cmd),然后键入:

"c:\Progam Files(x86)\GnuWin32\bin\awk"