• Software
  • Leadership
  • Agile
  • Events
  • Other Topics
    • Finance
    • Robotics & AI
    • System Administration
    • Books
    • Life Experiences
    • Environment
  • Write and Earn
  • About Us
    • About Us
    • Our Contributors
    • Contact Us
    • Article Submission Guidelines
    • Logo demystified
  • Follow @MeJaneve
    Janeve.Me
  • Categories

    Browse through following categories for articles written by professionals.
    • Agile
      4
    • Books
      5
    • Environment
      1
    • Events and Conferences
      7
    • Featured
      15
    • Finance
      1
    • Leadership
      5
    • Life Experiences
      8
    • Robotics & AI
      1
    • Software
      29
    • System Administration
      2
  • Software
  • Leadership
  • Agile
  • Events
  • Other Topics
    • Finance
    • Robotics & AI
    • System Administration
    • Books
    • Life Experiences
    • Environment
  • Write and Earn
  • About Us
    • About Us
    • Our Contributors
    • Contact Us
    • Article Submission Guidelines
    • Logo demystified
Home » System Administration

Interesting uses of awk command.

Janeve George Posted On November 4, 2014
0
1.9K Views


0
Shares
  • Share On Facebook
  • Tweet It

If you are new to the awk command, then I would suggest you read the article “A very quick introduction to AWK”. I love using the awk command to find stats from log files. I would like to share few of these interesting commands which has helped me finding some stats.

Test log file to process

I am taking following input from a log file named file.log for my example.

Completed processed item 1 (1.23s).
Completed processed item 2 (0.5s).
Completed processed item 3 (0.22s).
Completed processed item 4 (0.18s).
Completed processed item 5 (0.75s).
Completed processed item 6 (12.31s).
Completed processed item 7 (0.85s).
Completed processed item 8 (0.25s).

Finding sum of values or total time etc.

You could run this command to find the total time taken to process.

grep -E -o "\(([0-9\.]+)s\)" file.log | grep -E -o "[0-9\.]+" | awk '{ sum += $1 } END { print sum  }'

Finding average of values or average time etc.

You could run this command to find the average time taken to process.

grep -E -o "\(([0-9\.]+)s\)" file.log | grep -E -o "[0-9\.]+" | awk '{ sum += $1 } END { print sum / NR }'

Finding minimum and maximum of values or average time etc.

You could run this command to find the minimum time taken to process.

grep -E -o "\(([0-9\.]+)s\)" file.log | grep -E -o "[0-9\.]+" | awk '{ if (min > $1 || length(min) == 0) min = $1 } END { print min }'

You could run this command to find the maximum time taken to process.

grep -E -o "\(([0-9\.]+)s\)" file.log | grep -E -o "[0-9\.]+" | awk '{ if (max < $1) max = $1 } END { print max }'

 

Post Views: 1,932
0
Shares
  • Share On Facebook
  • Tweet It




Author

Janeve George

A Technology Leader, Software Engineer, and an Agile Methodologies enthusiast. Currently, working as Manager - Product Development with MediaKind India Pvt. Ltd. (previously Ericsson Media Solutions). He has more than a decade of experience spanning different verticals predominated by hosting, cloud and media delivery technologies.

Trending Now
Toolbox for System Designers
Janeve George March 6, 2020
The Standardized HTTP Client API in Java SE 11
Janeve George March 21, 2020
SOLID Design Principles
Read Next

SOLID Design Principles

  • Follow @MeJaneve
    Janeve.Me
  • Categories

    Browse through following categories for articles written by professionals.
    • Agile
      4
    • Books
      5
    • Environment
      1
    • Events and Conferences
      7
    • Featured
      15
    • Finance
      1
    • Leadership
      5
    • Life Experiences
      8
    • Robotics & AI
      1
    • Software
      29
    • System Administration
      2

  • Popular Posts

    • Scrum Roles and Responsibilities (41,755 Views)
    • Class.forName() and DriverManager.getConnection() (12,268 Views)
    • Daily Stand-up: What, How, Who and When. (11,255 Views)
    • Which Java collection to use? (11,013 Views)
  • Recent Posts

    • The Java Stream API
    • Functional Interfaces in Java
    • Online Webinar: Students & New Technology - 28th July 2020
    • Modular Programming in Java
  • Keep In Touch

    Follow us on social media to get latest articles on Programming, System Architecture, Agile Development Methodologies, Product and Project Management, Personal Development, BigData, Robotics, Upcoming Events and more...


Copyright © 2020 | Janeve.Me. All rights Reserved.
Press enter/return to begin your search