Code Monkey home page Code Monkey logo

shell-commands's Introduction

Here are some great useful commands to conduct the statistic analysis.

1. Process lines of a file in batch and apply mathematical computation.

1.1 Accumuate by a column($1 represents the first column).

awk '{sum+=$1};{print sum}' log 

will print out the sum at each step.

awk '{sum+};END{print sum}' log

will only print out the final step.

1.2 Above commands divide each column by \space or \tab by default. You can customize the division character by -F:

awk -F "," '{print $1}' log 

will divide each column by , and print out the first column.

1.3 Find the maximal or minimal value inside a column of a file.

awk 'BEGIN{first=1;} {if (first) { max = $1; first = 0; next;} if (max < $1) max=$1;} END {print max}' log

will print out the maximal value in the first column of the log.

awk 'BEGIN{first=1;} {if (first) { min = $1; first = 0; next;} if (min > $1) min=$1;} END {print min}' log

will print out the minimal value.

awk 'BEGIN{first=1;} {if (first) { max = min = $1; first = 0; next;} if (max < $1) max=$1; if (min > $2) min=$2; } END { print min,max}' log

will print put both minimal and maximal value.

1.4 Assign a variable the value taken from the first row

cat log |awk 'BEGIN{row=1}{if(row==1) {time=$3} printf("%0.0f\t%d\n", (($3-time)/60), ($2-$1)); row++}'

2. To kill a set of processes in a time, you can use xargs.

ps -ef |grep 'nginx' |awk '{print $2}' |xargs kill -9

will kill all the processes whose name contains nginx.

shell-commands's People

Contributors

likai1993 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.