Day 5/90 Days-of-DevOps challenge

Table of contents

No heading

No headings in the article.

AWK COMMAND IN LINUX

AWK is a command-line tool and a programming language used in Linux and other Unix-based operating systems. It is mainly used for text processing, data extraction, and reporting.

SYNTAX-awk options 'pattern {action}' file

-options: Optional parameters that specify how AWK should behave. -pattern: A condition that is tested against each line of the input file. If the pattern is matched, the corresponding action is taken. -action: A set of commands that are executed when the pattern is matched. -file: The name of the input file.

EXAMPLE FOR AWK-$ awk '{ print $1 }' data.txt

** This command prints the first field of each line in the data.txt file. The dollar sign followed by a number is used to refer to a specific field in the input file.

AWK can also be used to perform arithmetic operations, string manipulation, and conditional statements, among other things. It's a powerful tool for manipulating text data in a command-line environment.

1.]Arithmetic operations: AWK can perform arithmetic operations such as addition, subtraction, multiplication, and division. For example, the following command adds up the second field of each line in a file:

command-$ awk '{ sum += $2 } END { print sum }' data.txt

2.]String manipulation: AWK can manipulate text data by extracting substrings, replacing text, and converting cases. For example, the following command extracts the first two characters of the first field of each line:

command-$ awk '{ print substr($1, 1, 2) }' data.txt

3.]Conditional statements: AWK can use conditional statements such as if-else to perform different actions based on certain conditions. For example, the following command prints the first field of each line if the second field is greater than 10:

command-$ awk '{ if ($2 > 10) print $1 }' data.txt

#devops #90daysofdevops #cloud #kubernetes #linux #docker #devopstools