• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

awk command to search keyword or strings in file

June 5, 2014 by Sharad Chhetri Leave a Comment

In this tutorial we will learn, awk command to search keyword or strings in file . We will search single as well as multiple keyword with awk Command. This is a commonly used tips by most of the System Admin. Whereas the same result you can also find by using grep command.

Introduction of AWK Command

AWK is an interpreted programming language designed for text processing and typically used as a data extraction and reporting tool.AWK was created at Bell Labs in the 1970s and its name is derived from the family names of its authors – Alfred Aho, Peter Weinberger, and Brian Kernighan. (Reference : Wikipedia)

Before directly moving to steps part, have a look on file contents which we are using for this practical.

File Name : employee.list

linux@tuxworld:/tmp$ cat employee.list 
Emp-ID	Name	Designation	Dept.		Ext.
12	Joe	Manager		HR		2345
67	George	Developer	IT		8467
100	Ravi	Sysadmin	IT		9901
3789	Tina	Manager		Security	9948
1200	Justin	Supervisor	Fascility	1095
456	Katie	Executive	HR		6660
linux@tuxworld:/tmp$

Search single keyword with awk command

To search single keyword by using awk command, use below given syntax

awk '/Keyword/' /path/file-name

Example: Here we are searching keyword George and HR respectively.

linux@tuxworld:~$ awk '/George/' /tmp/employee.list 
67	George	Developer	IT		8467
linux@tuxworld:~$ 
linux@tuxworld:~$ awk '/HR/' /tmp/employee.list 
12	Joe	Manager		HR		2345
456	Katie	Executive	HR		6660
linux@tuxworld:~$ 

Search multiple keyword with awk command

To search multiple keyword by using awk command, use below given syntax

awk '/Keyword-1|Keyword-2|Keyword-3|Keyword-N/' ' /path/file-name

Example: We will search 3 Keywords in single awk command.

Keyword-1 = Ravi
Keyword-2 = Joe
Keyword-3 = Tina

linux@tuxworld:~$ awk '/Ravi|Joe|Tina/' /tmp/employee.list 
12	Joe	Manager		HR		2345
100	Ravi	Sysadmin	IT		9901
3789	Tina	Manager		Security	9948
linux@tuxworld:~$ 
linux@tuxworld:~$

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Search Keyword In Man Page Like We Search In vi / vim Editor
  2. grep command to find multiple strings or keyword from file
  3. search keyword in file with line number using grep command
  4. Search keyword in all available man pages – man command
  5. awk command to print columns from file
  6. cat,sed and awk commands to display file contents
  7. find command to search keyword in files recursively in linux
  8. sed command to display text between two strings or keywords
  9. sed : find the pattern (keyword) and delete the line from file
  10. grep command to show lines after and before the keyword

Filed Under: Linux, Linux Commands Tagged With: awk, linux command

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to use grep command to get fixed pattern or exact keyword

Forward all incoming emails to other SMTP server or gateway

Read the file inside compressed .gz files without extract

The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form

Edit the crontab without using crontab -e

How to configure ethernet in CentOS 6 after installing in Virtual Box

How To Get SSH Public Key Fingerprint Information

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy