• 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 » awk Command : Examples for SSH

By Abhishek Ghosh May 1, 2015 2:36 am Updated on May 1, 2015

awk Command : Examples for SSH

Advertisement

Here are Some awk Command Examples for SSH, Possibly the Most Commonly Used Command Line Interface for Many of the Webmasters and Developers. Previously, we published this kind of brief guide on some of the frequently used GNU/Linux commands like echo, unix pipeline or this can be a better example – combining unix pipeline with grep, cut commands. As the title of this article says, our examples are limited within – awk command examples for SSH. We will give examples with web server software, like nginx.

 

Basic Theory About awk Command

 

AWK was created in ’70s and is the acronym of the authors “ Alfred Aho, Peter Weinberger, and Brian Kernighan. It is pronounced as auk. When we are using all small caps – awk – it means we are talking about the program that runs scripts written in the AWK programming language. We use GNU AWK re-written by Paul Rubin, Jay Fenlason, and Richard Stallman in 1988. AWK was preceded by sed. AWK is a data-driven scripting language, in very short.

So, technically we should write the title of the guides in this fashion – awk Command : Examples for SSH not AWK Command : Examples for SSH. We are not scripting in AWK language.

Advertisement

---

 

awk Command : Examples for SSH

 

Suppose, in our Nginx config file, this line is present :

Vim
1
2
3
4
5
{
...
access_log   /var/log/nginx/thecustomizewindows.com.access.log;
...
}

First we will cd to the location /var/log/nginx/ and run this command :

Vim
1
awk '{print $3}' access.log  | sort | uniq -c | sort -r

Actually it works better it we have log_format well defined. We will get the digits of HIT, BYPASS, EXPIRED and MISS like a table. If there is dash – that can mean HTTP 403. The near same result can be achieved by running a cat command, this example of cat is by Rahul Bansal (RTCamp) :

Vim
1
cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -r

What that {print $3} part means? The command, awk ‘{foo}’ on foo file will apply the expression foo to each line of file and print the result to the terminal as standard output. awk splits its input lines on white space and saves each field as $1, $2 etc. awk reads each line of file foo and runs the script between {}. You can do a cat of Nginx config file or that default site config file :

Vim
1
cat /etc/nginx/sites-available/default

awk Command-Examples for SSH

Run these to for understanding :

Vim
1
2
awk '{print $3 }' /etc/nginx/sites-available/default
awk '{print $1+0.45 " " $2 " " $3 }' /etc/nginx/sites-available/default

Those $2, $3 are frankly, “field”.

If we wanted to get same result like that of cat against /etc/nginx/sites-available/default, then we should run :

Vim
1
awk '{print;}' /etc/nginx/sites-available/default

There is no suck command like :

Vim
1
awk /etc/nginx/sites-available/default

You’ll get syntax error. We can print how many server lines are there by :

Vim
1
awk 'END {print NR,"server"}' /etc/nginx/sites-available/default

NR stands for number of records. It is a standard. $0 variable represents the entire current line, so print and print $0 does exactly the same thing.

You can play with another example :

Vim
1
awk -F":" '{ print $1 $3 }' /etc/passwd

We using the -F option to specify ":" as the field separator. If we run :

Vim
1
awk -F":" '{ print $1 " " $3 }' /etc/passwd

then the individual results of $1, " " and $3 will get concatenated. root0 will look like root 0. Obviously we can use awk within the scripts, like this one for doing SSH on HP Cloud :

Vim
1
2
3
4
5
6
7
ssh -t root@10.12.14.16 <<'EOF'
awk '
    NR==1 {max=0;min=1}
    NR>1 {if (max<$3) max=3}
    END {print max}
' FS="," /path/to/foo
EOF

change to your IP address, else you’ll get banned by that IP’s server’s security system. man awk definitely going to help you.

Tagged With ssh awk , ssh and awk shell , ssh -i option examples , run complex awk command with ssh , merging ssh and awk , how to use ssh in awk , awk ssh commands , awk in ssh , awk field separator not working in ssh command , awk constructs with ssh

This Article Has Been Shared 168 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 awk Command : Examples for SSH

  • grep, cut Examples with unix pipe

    There are certain commonly used commands for managing Linux Servers. Here are some useful grep, cut examples with unix pipelining for SSH.

  • Select and Delete All Text of a File In SSH

    It is Quite Pathetic To Hold the Delete/Backspace Key of Any in Text Editor Like Nano or Vi in SSH Session. Here is a Practical Cheat Sheet.

  • Remove Expires: Thu, 19 Nov 1981 PHP Header in Ubuntu Server

    PHP is bad but more bad and not corrected is a bad Header. Here to Remove Expires: Thu, 19 Nov 1981 PHP Header in Ubuntu Server running Apache or Nginx.

  • Nginx Config Syntax Highlighting in Nano (Ubuntu)

    Normally, People Will Use SSH to Edit the Nginx Configuration Files. Here is How to Get Nginx Config Syntax Highlighting in Nano on Ubuntu.

  • Nano Syntax Highlighting : nanorc

    Nano Syntax Highlighting Can Be Forced With nanorc Files on All Linux Distro Like Ubuntu, CentOS, REHL, Arch Linux As Well As on OS X & BSD.

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

  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023
  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023
  • What is Vehicular Ad-Hoc Network? January 24, 2023
  • Difference Between Panel Light, COB Light, Track Light January 21, 2023

About This Article

Cite this article as: Abhishek Ghosh, "awk Command : Examples for SSH," in The Customize Windows, May 1, 2015, January 29, 2023, https://thecustomizewindows.com/2015/05/awk-command-examples-for-ssh/.

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