Search Results for: awk

Shell script: How to add multiple sequence numbers

This can be acheived in many ways. Through for loop Write a for loop using {}(know more about {} HERE) to mention the range of numbers and use let command to add those numbers. Below is the script which will uses for loop to add 1 to 100 numbers #!/bin/bashj=0for i in {1..100}dolet j=j+idoneprintf “Sum of 1 to 100 numbers is %d” $j Explination: for will take each number in to i variable and adds up to j for each loop and give you the final result in j as shown in above printf command.Note: Try to avoid echo command as much as possible as this is not protable.Through while loop: Loop will continue while the condition is true.   #!/bin/bash j=0i=0while [[ “$i” -le 100 ]]dolet j=j+i,i++doneprintf “Sum of 1 to 100 numbers is %d” $j Explination: While loop will check for condition that i less than equal to 100, the loop passes untill i reaches 100. let command is used to increment j and i. And then final value is stored in j. Through untill loop: Untill loop is similar to while loop but in reverse. Loop will happen untill the condition is true. #!/bin/bashj=0i=0until [[ “$i” -gt 100 ]]dolet j=j+i,i++doneprintf “Sum of 1 to 100 numbers is %d” $j Through awk scripting. seq 1 100 | awk ‘{ sum+=$1} END {print sum}’ Hope this helps to add...

Read More

Linux Directory Structure explained: /bin folder

This is second post in our Linux directory explanation series. /bin is one more important folder. Bin stands for binary which means an executable file. This folder contains commands or scripts or executable which can be executed to accomplish a task. We have some cousins to this folder as given below along with bin folder. /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin Let’s start with /bin folder. 1./bin folder /bin: Stands for binary. This folder contains base executables which are required for minimal system working. These commands are available in runlevel 1 for basic administration. Commands which are available in /bin folder is accessed by every one and can run by every user. This folder contains basic commands such as cat, chmod, chgrp, chown, date, dir, dd, df, ln, mv, echo and zipping tools such as bzip, gzip etc. 2./sbin folder /sbin: This folder stands for system binaries or super user binaries. This folder contains commands which are required for changing system properties or system level settings such as disk management, network management etc. This folder is accessed some times by normal user but they can not execute any of the commands located in this and what ever commands/scripts located in this folder are run only by root user. If you want to make normal user to run these commands you have to implement SUDO or Powerbroker to give elevated access. Some of the commands available...

Read More

Linux/Unix Bash shell script to find out machine/system IP address

This is a script which will show you IP address assigned to your machine. This script even take cares even if the host have multiple interfaces and shows the assigned IP address. #!/bin/bash#Purpose: To show the IP address of a machine#Author:Surendra Anne#Date: 2012-09-11#Licence: GPLv3for i in `ifconfig | cut -d” ” -f1 | sort | grep -v ‘^$’`doif ifconfig $i | grep addr: &> /dev/nullthenecho “The interface $i have IP Address:$(ifconfig $i | grep addr: | awk ‘{print $2}’ | cut -d”:” -f2)”fidone Your are free to add/modify this script and use it for your purpose. Some of the tools used here are SORT commandcut commandifconfig commandgrep commandredirection operationecho commandawk commandfor loopif...

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

Email Subscribe

ABOUT ME..!

My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.