• 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, cut Examples with unix pipe

By Abhishek Ghosh December 22, 2014 9:04 am Updated on December 22, 2014

grep, cut Examples with unix pipe

Advertisement

There are certain commonly used commands for managing Linux Servers. Here are some useful grep, cut examples with unix pipelining for SSH. We wrote about UNIX Pipe before, the reader must read that article if he/she is not aware of using pipe. Theoretical knowledge and practical management of a server differs hugely. We often do not type cd followed by space on Mac iTerm2, Homebrew Setup. We simply type / and hit the return key. If I am at Desktop on iTerm, and there is a directory named old-master, I can omit cd and simply type old-master and hit the return key. In bash shell there is an autocd option. You can enable it by using shopt -s autocd. It actually works on Ubuntu server. If you type /etc/php5/fpm/ (if exists), you’ll get -bash: /etc/php5/fpm/: Is a directory as output on Ubuntu Server. After running shopt -s autocd command, you can type /etc/php5/fpm/ to change directory.  Let us comeback to our topic – grep, cut examples with unix pipe.

 

grep, cut Examples with unix pipe : Basics

 

Basically, we should show examples of grep, then examples of cut and then use the unix pipeline. As usually, we can run man grep and man cut to learn the basics about the utilities. The official definition is – “The cut utility cuts out selected portions of each line from each file and writes them to the standard output. If no file arguments are specified, or a file argument is a single dash, cut reads from the standard input.” For example, if we run this command :

Vim
1
who | cut -c 1-16,26-38

The command who would return output like this on my Mac :

Advertisement

---

Vim
1
2
3
abhishekghosh console  Dec 14 20:03
abhishekghosh ttys000  Dec 21 23:57
abhishekghosh ttys001  Dec 15 00:05

When I am piping it via cut with arguments, I am getting this as output :

Vim
1
2
3
abhishekghosh coc 14 20:03
abhishekghosh ttc 21 23:57
abhishekghosh ttc 15 00:05

Basically we need a data, ideally a text file for easy example of cut. Let us wget Matt Cutts’ WordPress License :

Vim
1
wget https://www.mattcutts.com/blog/license.txt

This’ll extract only a desired column from the text file with -c option and displays the 2nd character from Matt Cutts’ WordPress License :

Vim
1
cut -c2 license.txt

It is quite bizarre output. You will get something like :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
h
r
o
i
u
 
R
 
h
n
 
h

Maximum probably possible usage of cut alone can be this example command extracts the fields in the file using a delimiter. The -d option in cut utility can be used to specify the delimiter (' ' here) and -f option is used to specify the field position :

Vim
1
cut -d' ' -f2,3 -f1 license.txt

You can compare :

Vim
1
cut -d'/' -f2,3 -f1 license.txt

The /download/source/ part from the url https://wordpress.org/download/source/ (last line in our case) will et vanished in our case.

Now, let see some examples of grep. grep prints lines of input matching a specified pattern. For example :

Vim
1
grep "General" license.txt

It will return a funny text with lines containing “General”. This is important as this command :

Vim
1
curl -I https://thecustomizewindows.com

returns a huge output, but we need to check whether the website is HSTS Preloaded or not. So, we can simple grep “Strict” :

Vim
1
curl -I -s https://thecustomizewindows.com | grep "Strict"

If you run :

Vim
1
curl -I -s https://thecustomizewindows.com | grep "HTTP"

It will return HTTP/1.1 200 OK, but if domain is redirecting with 301, it will return only that :

Vim
1
curl -I -s http://jima.in | grep "HTTP"

grep, cut Examples with unix pipe

 

grep, cut Examples with unix pipe : Combined

 

This was our basic goal to learn. grep will do some desired work, cut will filter the desired stuffs from that desired work. Unix Pipe will help. For example, this will return only the number of the HTTP status :

Vim
1
curl -I -s https://thecustomizewindows.com | grep "HTTP" | cut -c10,11,12

Actually you can grep again :

Vim
1
curl -I -s jima.in | grep "HTTP" | cut -c10,11,12 | grep "301"

The above is a bogus way of using the utilities because we could grep "301" before. That we shown for example only. Syntax Highlighting, however will colorize the texts. There are very powerful usages, depending on the need.

Tagged With grep cut , grep pipe to cut , grep with cut , unix cut command with pipe , cut some places after grep linux , using a pipe with the cut command , cut command grep , cut before piping linux , bash pipe cut , bash cut examples
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, cut Examples with unix pipe

  • Examples of Pipe or Pipelines Command

    In UNIX, Unix like operating systems including Linux, the shell of the OS have a mechanism called pipe or pipeline which looks like this |.

  • grep command : Details, Examples and Usages of Grep Command

    grep command for a program of UNIX and Unix like Operating System. It is used to search and filter. Historically, the name evolved from the command g / re / p.

  • Adding Help & Option in Bash Script

    Many New Hobbyist Programmers and Students Write Bash Scripts. Adding Help & Option in Bash Script is Easy. Here is Basic Guide With Example.

  • Command Prompt Commands : Alphabetical list of all commands in Windows 7

    Command Prompt Commands in Windows 7 provides the user access to 180+ command line commands. Here is a list of 200 Command Prompt Commands in Windows 7.

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.

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

  • How to Create a PHP Installer Script to Create Tables in MySQL DatabaseJune 4, 2023
  • What is Desktop Publishing (DTP)?June 3, 2023
  • Dynamic WebP Image Delivery in WordPress with Bunny CDNJune 3, 2023
  • Advantages and Disadvantages of Ubuntu Server DistributionJune 2, 2023
  • Typography on the WebJune 2, 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

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