Showing posts with label Linux Shell Scripting. Show all posts
Showing posts with label Linux Shell Scripting. Show all posts

Friday, September 14, 2018

AWK Command - In an Easy way




Awk stands for Aho Weinberger and Kernighan. Awk is a scripting language to process and analyze files.
Some of the features of Awk are given below :
  • Awk actually work on data files.
  • Awk can generate formatted output.
  • Awk support different regular expressions.
  • Awk allows different features of traditional programming language like conditions, operators, loop , functions and so on.
Syntax of Awk command
  1. awk 'program' input_file
The simplest program is the sequence of actions. Each action has either pattern or no pattern. Each action is enclosed with braces. We explain with a typical file named input.txt that contains name , age and height like this :
  1. Mehedi 01 WDE 25000
  2. Arafat 02 WDE 27000
  3. Baki 03 SDE 30000
  4. Mahbub 04 ADE 29000
  5. Nazmul 05 SDE 24000
If action has pattern , then matches that pattern with files line by line until end of file and print the matches lines. Example :
  1. awk '$4>=25000 {print $1, $2 }' in.txt
Output are given below
  1. Mehedi 01
  2. Arafat 02
  3. Baki 03
  4. Mahbub 04
Otherwise, action is performed for all lines of input file.
  1. awk '{print $1, $2 }' in.txt
Output are given below :
  1. Mehedi 01
  2. Arafat 02
  3. Baki 03
  4. Mahbub 04
  5. Nazmul 05
We can also write program that has only pattern and action is missing. For these programs the matched line is printed. But it is not a good practice to write only pattern without action.
  1. awk '/WDE/' in.txt
Output :
  1. Mehedi 01 WDE 25000
  2. Arafat 02 WDE 27000
Some points about printing :
  • At the time of printing the all field of input lines we just write print.
  1. awk '{print }' in.txt
  • Otherwise we write print and particular column number with dollar sign like $1. For more column we obviously use comma as a separator.
  1. awk '{print $1, $2 }' in.txt

Thursday, September 6, 2018

Interesting facts about ~/Linux

Some facts about Linux
  • In 2000 Steve Jobs Offered Linus Torvalds a job at APPLE on the condition that he should stop the development of Linux, But Linus refused to join and continued developing his product.
  • Microsoft was very much not impressed by its open source systemswhich were criticized badly but later it was sponsored by Microsoft itself.
  • Android is the highest using operating system on the planet with 2 billion people but Android runs on Linux.
  • Linux is very late that it released after three years of it's announced date.
  • Linux is the only operating system named after its founder Linus Torvalds
  • Linux has 20,323,379 lines of code which was pretty small in the version of the kernel.
  • Linux first name was “FreaX” which was a combination of “free”, “freak” and “Unix”)
  • Google, Intel, Huawei, Samsung, Red Hat, Canonical and Facebookare among the top contributors to Linux kernel development in recent years.
  • 9 out of top 10 public cloud infrastructures run on Linux.
  • IBM chose Linux for what is expected to be the world’s most powerful supercomputer, Sequoia.
  • All major closed source Operating Systems track user information while Linux distros generally don't, which means better user Security and Privacy is assured.

AWK Command - In an Easy way

Awk stands for Aho Weinberger and Kernighan. Awk is a scripting language to process and analyze files. Some of the features of Awk ...