Search

Linux AWK command Advance CLI

Greeting everyone! Hope Everything is going well Today In this blog we are going to see How to Use the AWK command in a CLI Scripting language which uses for manipulating data from given files and strings and which easily generates reports. In this blog, you will learn How to utilize the AWK command Interface.

What is AWK?

Basically, AWK Is a command based on the domain-specific design for text processing which is used for manipulating data and reporting tools. its works as a filter which is the default in any Linux/Unix system. The version of AWK that GNU/Linux distributes is written and maintained by the Free Software Foundation (FSF); it is often referred to as GNU AWK.

Advantages Of AWK?

It can file One by one Line
Splits each input line into fields
It Compares input lines/fields to patterns.
Performs actions on matched lines as user-supplied.
It’s based on Arithmetic and string operations.

AWK is very simple to use we can use AWK from our command Line Now, to check whether AWK Is installed in Your OS Or not run the command: -> awk -h (it will give instructions on the Usage of awk)

Now assume we have file.txt which contains the following data

1. Pallab class 23
2. Sam class 25
3. Rahul class 2
4. Jerry class 4
5.Meaco class 5

Now Let’s print all data from the given file using awk which we can Utilize here we will use the command: -> awk ‘print’ file.txt

Now, Utilize awk to match the given pattern here it will match the string according to the user’s want here, we will use the command: awk ‘/your match/ {print}’ file.txt

As the above result we see we manipulate replace One can use the above syntax for printing lines with a specific pattern. For example, if you want to print lines having the letter ‘o’ you have to add simply add ‘o’ in place of “variable to be matched”.

Now print a line from a given file using awk which has more than 18 length values AWK provides a built-in length function that returns the length of the string according to user supply. here we will use command: awk ‘length($0) > 18’ file.txt

As the above result, we see using awk we manipulate value by supplying length 18 that Eg: we need a line which has more than 18 length value if a line has more than 18 characters, then the comparison results are true and the line gets printed.

As We discussed Basic AWK Programming As how we can interface using awk using our CLI. The awk command in Linux helps the programmer to write a useful program. hope You learned Something new.

For References: https://www.tutorialspoint.com/awk/awk_discussion.htm

Thanks For Reading……. See You In Another Blog!

Stick With Our Blog: Click Here

Author

Pallab Jyoti Borah

VAPT Analyst

Table of Contents

Social Media
Facebook
Twitter
WhatsApp
LinkedIn