---
title: "COMPLETE OVERVIEW ON LINUX AWK COMMAND"  
description: "The basic syntax of the awk command is awk 'pattern {action}' filename."  
author: "HKR TRAININGS"  
published: 2023-04-04  
updated: 2023-04-05  
canonical: https://www.mindstick.com/articles/332288/complete-overview-on-linux-awk-command  
category: "software"  
tags: ["what is linx awk command"]  
reading_time: 3 minutes  

---

# COMPLETE OVERVIEW ON LINUX AWK COMMAND

The Linux AWK Command is a powerful text processing tool that allows you to manipulate and [analyze text](https://answers.mindstick.com/qa/102651/how-does-google-s-cloud-automl-natural-language-analyze-text) data in a variety of ways. The general syntax of the AWK command is:

\

arduino

Copy code

awk 'pattern {action}' filename

where:

\

pattern is a [regular expression](https://www.mindstick.com/forum/12854/how-to-solve-regular-expression-for-validating-id-in-c-sharp-asp-dot-net) or a [logical expression](https://answers.mindstick.com/qa/31222/which-process-makes-different-logical-expression-looks-identical) that matches certain lines in the input file

action is a series of commands that are executed on the lines that match the pattern

filename is the name of the input file

Here are some examples of how to use AWK:

\

Print the first field of each line in a file:

arduino

Copy code

awk '{print $1}' filename

Print the lines that contain a certain pattern:

arduino

Copy code

awk '/pattern/{print}' filename

Print the total number of lines in a file:

arduino

Copy code

awk 'END{print NR}' filename

Print the sum of values in the second column of a file:

arduino

Copy code

awk '{sum+=$2} END{print sum}' filename

These are just a few examples of what you can do with AWK. The possibilities are endless and you can use AWK to perform complex [data processing](https://answers.mindstick.com/qa/114514/what-is-the-significance-of-edge-computing-in-enhancing-data-processing-and-reducing-latency) tasks.

\

## BASIC SYNTAX FOR AWK COMMAND:

\

The basic syntax for the awk command in Linux is:

\

arduino

Copy code

awk 'pattern {action}' filename

pattern: A pattern is a regular expression that specifies which lines to process. If the pattern matches the current line, then the associated action is executed.

{action}: This is a set of commands that are executed on the lines that match the pattern.

filename: This is the name of the file(s) to process.

Some common options that can be used with the awk command include:

\

-F: This option specifies the field separator. By default, awk treats whitespace as the field separator, but with -F, you can specify a different delimiter.

-v: This option allows you to set a [variable value](https://www.mindstick.com/interview/23485/exchange-two-integer-variable-value-without-using-third-variable) before running the awk script.

Here's an example of how to use the basic syntax of the awk [command to print](https://www.mindstick.com/interview/33829/write-a-sql-command-to-print-a-string-in-reverse-order) the first column of a file:

\

arduino

Copy code

awk '{print $1}' filename

In this example, the pattern is not specified, so the action will be applied to every line of the file. The action {print $1} tells awk to print the first field of each line. The field separator is whitespace, which is the default.

\

Here's another example that shows how to use a pattern with the awk command to print lines that contain a specific string:

\

arduino

Copy code

awk '/pattern/ {print}' filename

In this example, the pattern is /pattern/, which means that awk will only execute the action for lines that contain the string "pattern". The action is {print}, which tells awk to print the entire line.

\

These are just a few examples of how to use the awk command in Linux. Awk is a powerful tool that can be used to perform complex text processing tasks.

\

---

Original Source: https://www.mindstick.com/articles/332288/complete-overview-on-linux-awk-command

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
