- 1 year ago
Command line - Awk command for Windows
AWK is a powerful text processing tool commonly used in Unix-like environments. However, Windows does not have AWK built-in by default. To use AWK on Windows, you can follow these steps:
Install Gawk:
The GNU AWK (Gawk) utility is available for Windows as a standalone package. You can download Gawk for Windows from the following link:https://sourceforge.net/projects/gnuwin32/files/gawk/
After downloading, install Gawk by running the installer executable.
Add Gawk to PATH:
After installation, add the Gawk installation directory to your system's PATH environment variable. This will allow you to run Gawk from any command prompt.Use Gawk:
Open a Windows Command Prompt or PowerShell and use Gawk as you would in a Unix-like environment. For example:shgawk '{ print $1 }' input.txt
Replace
input.txt
with the name of the file you want to process, and{ print $1 }
with the AWK script you want to run.Batch Script with Gawk:
You can also create batch scripts with Gawk commands and run them using the Windows Command Prompt. Save the Gawk commands in a.bat
file and execute the batch script.
Please note that Gawk on Windows might have some differences from AWK on Unix-like systems, so it's recommended to refer to Gawk's documentation for any Windows-specific considerations.
Keep in mind that Windows Subsystem for Linux (WSL) provides a more native Unix-like environment on Windows, including AWK, and might be a better choice if you frequently work with Unix tools.