• 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

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 Commands

Search keyword in all available man pages – man command

There are unfinished transactions remaining. You might consider running yum-complete-transaction

Yum command to download rpm file without installing in linux system

Save iptables permanently on Ubuntu

How to test rpm package before installation

semanage command not found in CentOS 6 and RHEL 6

Learn tar command and know about its precaution

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

master admin password openerp 7.x

convert space into new line using sed command

Error: Could not stat() command file ‘/var/lib/nagios3/rw/nagios.cmd’!

Replace keyword with its filename without extension : bash script

How to reset forgot root password in CentOS 6.x and Redhat 6.x

configure: error: C++ compiler cannot create executables

Yum Error database disk image is malformed

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Internal External Command

What is Linux/Unix Internal And External Command

Linux basic command

Linux Basic Commands With Examples For Every Beginner

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)

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

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