Bash Command : cat and awk

This Bash command reads the content of the “config.yaml” file using `cat` and then uses `awk NF` to print only the non-empty lines of the file. The `NF` in `awk` stands for the number of fields, so `awk NF` prints lines that have one or more fields (non-empty lines).

More explanation 👇👇

Let’s break down the command:

1. `cat config.yaml`: This part of the command uses the `cat` command to concatenate and display the content of the “config.yaml” file.

2. ` | `: This is a pipe symbol, which takes the output of the command on its left (in this case, the content of “config.yaml”) and passes it as input to the command on its right.

3. `awk NF`: This part utilizes the `awk` command with the condition `NF` (number of fields). In AWK, `NF` represents the number of fields in a line. When used as a condition, it evaluates to true for lines with one or more fields (non-empty lines).

So, combining these parts, the entire command takes the content of “config.yaml,” passes it through `awk NF`, and prints only the lines that are not empty (lines with one or more fields).

Leave a comment

Design a site like this with WordPress.com
Get started