awk

Introduction

In this article you can learn mainly about working with AWK.

You can read about SED in the article «SED basics» and about GREP in the article GREP

By default I assume that you work in Bash on Windows 10

How to install Bash in Windows 10 is described in detail here

Basic AWK commands

Print only certain columns

Suppose we have a file input.txt with the following content

Here is a String it has a Name Here is an Integer it has a Name Here is a Float it has a Name

We want to drop everything to the left of the word it, including the word it, and write the result to a file.

We did a similar operation with sed in this example.

awk '{print $6,$7,$8}' > awk_result.txt

$6 means that we print the element from the sixth column. Result:

 has a Name  has a Name  has a Name

With awk we can print arbitrary columns:

awk '{print $1,$3,$7,$8}' > awk_result.txt

Result:

Here a a Name Here an a Name Here a a Name

Article author: Andrei Olegovich