Cyberithub

How to Install Gawk on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, we will see how to install gawk on ubuntu 20.04 LTS. GAWK is a free and open source GNU utility which interprets a special-purpose programming language that makes it possible to handle certain data formatting task using just few lines of code. It provides a clear edge over some of the prominent programming languages such as C and Pascal when it comes to make certain changes in text files or extract some data using just few lines of code. It can be easily installed in almost all the famous Linux distributions. Here we will see the steps to install Gawk on Ubuntu 20.04 LTS based systems.

 

How to Install Gawk on Ubuntu 20.04 LTS (Focal Fossa)

How to Install Gawk on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Install Ytdownloader on Ubuntu 20.04 LTS (Focal Fossa)

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your Server.

 

Step 2: Update Your Server

Before proceeding with the steps to install Gawk in your system, it would be wise to first update and upgrade all the installed packages to the latest version by using sudo apt update && sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Get:1 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,075 B]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [541 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1,950 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [408 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [319 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [59.9 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages [575 kB]
.......................................................

 

Step 3: Install Gawk

In the next step, you can install gawk utility from default Ubuntu repo by using sudo apt install gawk command as you can see below. This will download and install the package along with all its dependencies.

Advertisements
cyberithub@ubuntu:~$ sudo apt install gawk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libpython3.9-minimal libpython3.9-stdlib python3.9-minimal
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libsigsegv2
Suggested packages:
gawk-doc
The following NEW packages will be installed:
gawk libsigsegv2
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 431 kB of archives.
After this operation, 1,752 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libsigsegv2 amd64 2.12-2 [13.9 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/main amd64 gawk amd64 1:5.0.1+dfsg-1 [418 kB]
Fetched 431 kB in 1s (389 kB/s)
Selecting previously unselected package libsigsegv2:amd64.
(Reading database ... 256296 files and directories currently installed.)
Preparing to unpack .../libsigsegv2_2.12-2_amd64.deb ...
Unpacking libsigsegv2:amd64 (2.12-2) ...
Setting up libsigsegv2:amd64 (2.12-2) ...
Selecting previously unselected package gawk.
(Reading database ... 256303 files and directories currently installed.)
Preparing to unpack .../gawk_1%3a5.0.1+dfsg-1_amd64.deb ...
Unpacking gawk (1:5.0.1+dfsg-1) ...
Setting up gawk (1:5.0.1+dfsg-1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

 

Step 4: Check Version

After successful installation, you can check the installed version of gawk by using gawk --version command as shown below.

cyberithub@ubuntu:~$ gawk --version
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
Copyright (C) 1989, 1991-2019 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

 

Step 5: Using Gawk

Now that you have gawk installed in your system, it is time to test the utility. You can simply query your /etc/passwd file and display the first column based on colon(:) field separator(-F) using gawk -F ":" '{print $1}' /etc/passwd command as shown below.

cyberithub@ubuntu:~$ gawk -F ":" '{print $1}' /etc/passwd
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
.......................................

 

Step 6: Check all the Available Options

If you are looking to check all the options available with gawk command then you need to use gawk --help command as shown below.

cyberithub@ubuntu:~$ gawk --help
Usage: gawk [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk [POSIX or GNU style options] [--] 'program' file ...
POSIX options: GNU long options: (standard)
-f progfile --file=progfile
-F fs --field-separator=fs
-v var=val --assign=var=val
Short options: GNU long options: (extensions)
-b --characters-as-bytes
-c --traditional
-C --copyright
-d[file] --dump-variables[=file]
-D[file] --debug[=file]
-e 'program-text' --source='program-text'
-E file --exec=file
-g --gen-pot
-h --help
-i includefile --include=includefile
........................................

Leave a Comment