• 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

search keyword in file with line number using grep command

December 8, 2013 by Sharad Chhetri Leave a Comment

grep command which is used for searching the keyword in file and show its output as lines containing a match to the given PATTERN or Keyword. When we simply use grep command without using any switches it simply shows the output with line having the keyword.Today,in this post we will know about a small tip to search keyword in file with line number using grep command .

To get the line number by using grep command. Use the below given syntax.

Syntax:

-n = switch to display line number

grep -n KEYWORD file-name

Example:

In below given example. You can see, 7: 11: 18: these refer as line number whereas keyword AllowOverride is found in file /etc/apache2/sites-enabled/000-default

root@tuxworld:~# grep -n AllowOverride /etc/apache2/sites-enabled/000-default 
7:		AllowOverride All
11:		AllowOverride All
18:		AllowOverride None
root@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. Do not show line haveing particular keyword by grep command
  3. grep command to find multiple strings or keyword from file
  4. awk command to search keyword or strings in file
  5. How to use grep command to get fixed pattern or exact keyword
  6. grep command to show lines after and before the keyword
  7. find command to search keyword in files recursively in linux
  8. Search keyword in all available man pages – man command
  9. sed : find the pattern (keyword) and delete the line from file
  10. grep command to remove blank lines from file

Filed Under: Linux Tagged With: grep

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

Print double hyphen sign simultaneously in post of Octopress

How to find swap partition or file in linux

Terminal Recording with script and scriptreplay command

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

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

Keep logs of user after sudo su – : Secondary Logging

How to convert float to integer number

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