• 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
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

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Changing Data With cURL for OpenStack Swift (HP Cloud CDN)

    Changing Data With cURL For Object is Quite Easy in OpenStack Swift. Here Are Examples With HP Cloud CDN To Make it Clear. Official Examples Are Bad.

  • OpenShift OctoPress Auto install Script

    OpenShift OctoPress Auto install Script is an Advanced Script to Run OctoPress on Free OpenShift PaaS Practically Without Any Knowing Ruby or Git.

  • OpenStack Swift & HPCloud CDN PHP Bindings : Basics

    Here is the basics of OpenStack Swift & HPCloud CDN PHP Bindings for the WordPress Plugin developers and those who works with PHP based CMS.

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

  • Implementation of Requirements in Electronic Archiving SystemsDecember 2, 2023
  • What is Database ArchivingDecember 1, 2023
  • Problems of Search EngineDecember 1, 2023
  • How Search Engine WorksNovember 30, 2023
  • Data Mining: An OverviewNovember 30, 2023
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