• 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
      9
    • Finance
      1
    • Leadership
      6
    • Life Experiences
      8
    • Robotics & AI
      1
    • Software
      30
    • 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
2.4K 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: 2,380
0
Shares
  • Share On Facebook
  • Tweet It




Author

Janeve George

A Technology Leader, Software Engineer, and Agile Methodologies enthusiast. Currently, working as Lead Software Development with Zeta Suite. He has more than 1.8 decades of experience spanning different verticals predominated by hosting, cloud, and media delivery technologies.

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
      9
    • Finance
      1
    • Leadership
      6
    • Life Experiences
      8
    • Robotics & AI
      1
    • Software
      30
    • System Administration
      2

  • Popular Posts

  • Recent Posts

    • 3Es to Supercharge your Career Journey and Performance Review Ratings
    • Java Asynchronous Programming using CompletableFuture - Part 1
    • The Java Stream API
    • Functional Interfaces 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