Awk: Difference between revisions

From TÜ Narva Kolledži Wiki
Jump to navigation Jump to search
Content deleted Content added
Dzikajev (talk | contribs)
Created page with "Igor Dzikajev"
 
Dzikajev (talk | contribs)
No edit summary
Line 1: Line 1:

Igor Dzikajev
<span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span>
<h1>What is <span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span> command?</h1>
<span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span> is a scripting language, and it is helpful when working in the command line. It's also a widely used command for text processing.
When using <span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span>, you are able to select data – one or more pieces of individual text – based on a pattern you provide.

For example, some of the operations you can do with <span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span> are searching for a specific word or pattern in a piece of text given, or even select a certain line or a certain column in a file you provide.

<h1>The Basic Syntax of the <span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span> command</h1>
In its simplest form, the <span style="background:gray;padding:2px;border-radius:5px;color:white;">awk</span> command is followed by a set of single quotation marks and a set of curly braces, with the name of the file you want to search through mentioned last.

It looks something like this:
<p style="background:rgba(50,50,50,0.1);padding:10px;">awk '{action}' your_file_name.txt</p>
When you want to search for text that has a specific pattern or you're looking for a specific word in the text, the command would look something like this:
<p style="background:rgba(50,50,50,0.1);padding:10px;">awk '/regex pattern/{action}' your_file_name.txt</p>

With test file looking like this:
<p style="background:rgba(50,50,50,0.1);padding:10px;white-space:pre;">fristName lastName age city ID

Thomas Shelby 30 Rio 400
Omega Night 45 Ontario 600
Wood Tinker 54 Lisbon N/A
Giorgos Georgiou 35 London 300
Timmy Turner 32 Berlin N/A</p>

Revision as of 17:38, 13 December 2022

awk

What is awk command?

awk is a scripting language, and it is helpful when working in the command line. It's also a widely used command for text processing. When using awk, you are able to select data – one or more pieces of individual text – based on a pattern you provide.

For example, some of the operations you can do with awk are searching for a specific word or pattern in a piece of text given, or even select a certain line or a certain column in a file you provide.

The Basic Syntax of the awk command

In its simplest form, the awk command is followed by a set of single quotation marks and a set of curly braces, with the name of the file you want to search through mentioned last.

It looks something like this:

awk '{action}' your_file_name.txt

When you want to search for text that has a specific pattern or you're looking for a specific word in the text, the command would look something like this:

awk '/regex pattern/{action}' your_file_name.txt

With test file looking like this:

fristName lastName age city ID Thomas Shelby 30 Rio 400 Omega Night 45 Ontario 600 Wood Tinker 54 Lisbon N/A Giorgos Georgiou 35 London 300 Timmy Turner 32 Berlin N/A