• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » grep command : Details, Examples and Usages of Grep Command

By Abhishek Ghosh April 27, 2013 6:53 am Updated on October 17, 2014

grep command : Details, Examples and Usages of Grep Command

Advertisement

grep command is for the program for usage in command line for UNIX and and Unix derivatives which is used to search and filter strings from from a junk of files.It was originally developed by Ken Thompson in 1973. The term grep stands for g lobal / r egular e xpression / p rint or g lobal search for a r egular E xpression and p rint out matched lines : “global search for a regular expression and print matching lines.” Historically, the name grep or grep command evolved from the command g / re / p from the standard UNIX editor ed. There are many variants such as egrep, fgrep and agrep.

 

Introduction to grep command and program

 

On grep command, a small website can be created. The following articles falls among Suggested Reading for the new users :

  1. Linux Commands and UNIX Commands for Server
  2. List of Indispensable OS X Commands
  3. UNIX Operating System
  4. Unix like Operating System

 

Grep command comes under BSD General Commands Manual and documentation can be found on Apple’s developer portal :

Advertisement

---

 

Vim
1
https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/grep.1.html

 

In the command line grep is used mostly for searching files. Grep command pick out rows in which the pattern is included as a word, the line numbers, and output the file names of all files that contain the specified text. As written on manual page :

 

Vim
1
grep, egrep, fgrep, zgrep, zegrep, zfgrep -- file pattern searcher

 

In other words, you can search for a file, a folder, a word inside a text file etc. Regular expressions can be used with grep command. Output can be saved as usually.

 

Examples of usage of grep command

 

man means manual, so running the man grep command in command line will give you a basic usage’s manual. If I want to search for log folder in the server, I can run using this pattern :

 

grep term-to-search where-to-search

 

it will become :

 

Vim
1
grep log *

 

It will not only show the locations but also tell me whether they are directories or files. This is useful if you can not find a folder on server. In WordPress forum, new users often asked to locate the php log folder – they asks as cross question – where is log folder ? The ‘WordPress Developers’ has excellent knowledge (pun intended), they replies – “ask your webhost”. You can simply put a php script to find the log folder – grep command can be scripted and not necessarily needs shell access (like curl, wget etc.). Technically it can be used for searching webpages creating a script. Note : recursive (-r) should be added to searching the directories. The above is a simple example.

 

grep command
 

Now, take that I found the log file. But I want to know how many times the digit 500 has been shown, -c is for count :

 

Vim
1
grep -c "500" log.txt

 

Now I noticed that, in the 500 -ed result, there is need to exclude some results. That can be done. We can search a device name too. We can use color :

 

grep -r Abhishek /Users --color

 

Avoid using -i and -r ; it can create logical clash depending on the command. But my mother also wants to search with the Same Word, so in that case I will save the search as text file :

 

grep (put your options) >> filename.txt

 
Abhishek-Ghosh

Tagged With grep command usages , grep command in detail , grep command , grep -o command usage , grep -q command , GREP -L UNIX , grep command ! and & , grep -B command , grep command in unix with details , detail in grep command

This Article Has Been Shared 800 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to grep command : Details, Examples and Usages of Grep Command

  • Install WordPress on Mac OS X With Command Line LAMP Configuration

    Install WordPress on Mac OS X Without installing MAMP or AMPPS from Command Line just like we do for Ubuntu or any kind of Linux. Mac has PHP and virtual hosts.

  • List of Indispensable OS X Commands

    List of Indispensable OS X Commands lists some important commands for the newbies to Apple Mac OS X 10.8 Lion. This is a small list of commands normally used.

  • UNIX Operating System : Brief Technical Perspective

    UNIX Operating System is a multi-user operating system released in August 1969 by Bell Laboratories to support the development of softwares. Here is some words.

  • ARM Architecture : The Processor Behind Smartphones and Tablets

    ARM Architecture is currently most widely used Processor architecture for embedded and mobile devices. But they are being in consideration for the servers too.

  • WordPress Command Line Tool : Install and Run Commands

    WordPress Command Line Tool can be installed on any UNIX or UNIX Like OS. The usage ranges from installing a plugin, Publishing Post to anything you want.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is ChatGPT? February 3, 2023
  • Zebronics Pixaplay 16 : Entry Level Movie Projector Review February 2, 2023
  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023
  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023

About This Article

Cite this article as: Abhishek Ghosh, "grep command : Details, Examples and Usages of Grep Command," in The Customize Windows, April 27, 2013, February 5, 2023, https://thecustomizewindows.com/2013/04/grep-command-details-examples-and-usages-of-grep-command/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT