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

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

  • Steps To Install Nginx Plus on Ubuntu Server (HP Cloud)

    Here Are the Steps To Install Nginx Plus on Ubuntu Server Running on HP Cloud. Nginx Plus is the Paid Version of Nginx with Extra Features.

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

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

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 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