Bash Script : Print lines of a file in reverse order

The task is to print the lines of a file in the reverse order in which it appears in the file. A bash script and some other tricks would be presented below to do this. We can do this with tac and sed , but here we will do it without any of these tools and use only the bash inbuilt, bash arrays, and redirection.
Check out the post for the script

Bash Script : Finding Digital Root of an Integer

To find a digital roots of an integer is a very common question in high school when doing introductory programming. Digital roots are defined as follows. First an integer is taken if the number of digits are greater than 1, then the sum of its digits are done, if the sum has more than one digits then again the sum of digits are done, and so on until a sum of digit has only 1 digit. This last value of the sum of digits containing a one digit value is defined as the digital root of a number. First we describe in brief what a digital root is then present a shell script.
Continue reading “Bash Script : Finding Digital Root of an Integer”

Little and Big Endian conversion

Problem: Convert an integer from a given endian to its opposite endian

Endian

In computation endian refer to the ordering of bytes within a single word of 16-bit, 32-bit, or 64-bit. A 16-bit word contains 2 bytes. Say 0x12AB is a 16-bit hexadecimal integer. It’s most significant byte is 12 and the least significant byte is AB. When it is stored with the most significant byte 12 first in lower memory address, and the least significant byte AB is stored next to it, in higher memory address, then this storing format is called the big-endian. If the leas significant byte AB is stored first in higher memory address and the most significant byte is stored next to it, that is in the lower memory address then this format is known as the little-endian. Similarly for a 32-bit word say 0x1A2B3C4D , for little-endian format the least significant byte 4D would be stored first in lower memory address, and next would be 3C, next 2B and then at last the most significant byte would be stored 1A.

Continue reading “Little and Big Endian conversion”

Bash Script : Check for palindrome

When learning shell script, a very common script which is given as a task in schools is to write a script to check if a string is a palindrome or not. I am presenting two solutions of this simple problem. A palindrome is a string whose reverse is same as the string itself. Like “madam” is a palindrome but “hello” is not

Continue reading “Bash Script : Check for palindrome”

Floating point math operations in bash

When writing scripts in bash, sometimes we need to work with basic math functions. Like the trigonometric functions, square root, cube root, logarithms. Bash does not support floating point operations. This is where the problem is encountered, and we cannot write a math function of our own. There must be a way to do this, and yes. Bash supports redirections so we can feed the floating point computations and the math functions into some other program’s input who understands it. The program which can be used is the bc, which is an arbitrary precision calculator language. bc can do floating point operations, and also can do basic math functions. With bash and bc we can do the above. Continue reading to know how.

Continue reading “Floating point math operations in bash”

CD Tray Open/Close infinite loop

Just feel the annoyance and irritation when the CD tray of your computer opens and closes, opens and closes, again and again, again and again, and does not stop until you shut down the computer. We will be writing a tiny shell script with which we would do the above stuff. Although this is very cruel if you apply this to some one, then please be sure to fix it before he/she shoots you with a 50 caliber rifle. So keep on reading to know how to make the simple script to make an infinite CD-ROM tray open close loop in GNU+Linux

Continue reading “CD Tray Open/Close infinite loop”

Beginners Guide to GCC

GCC is the default compiler in the GNU+Linux systems, and is used to compile small applications, big softwares, and the kernel. Often beginners are overwhelmed with the amount of information provided in the gcc manual. This tutorial highlights the most useful commands and describes how to use them, how to read warnings and errors from the compiler output and compile the C Language sourcecodes with gcc. This tutorial does not cover advanced options and topics, in depth details are avoided. This tutorial will give the basic idea, and after reading this i hope that the manual pages would be easier to read.

Continue reading “Beginners Guide to GCC”

All Combinations Without Repetitions

Problem : To generate all Combinations of a set of distinct elements

Before we start discussing about the implementation we will go through the basic definitions of Combinations. Then we discuss the method to generate all the Combinations with examples and descriptions. Then the source code to implement the method will be presented. Continue reading.

Continue reading “All Combinations Without Repetitions”

Make a website block virus

We will make a “virus” which will block orkut, facebook, google, gmail, twitter and some others in Microsoft Windows systems. This is a very easy to code and effective one, and very good to play prank with friends. But before anything you do, please note that I will NOT be liable for any kind of damage done to any computer system or any other physical or intellectual property. You and only you are liable for everything. Sorry for the message, but i personally do not think such things will happen. To make sure such things do not happen, do not apply this to any man who does important works with the sites which are blocked and whoever you apply this upon, remember to unblock the sites shortly. The antidote is also supplied with this post.

Continue reading “Make a website block virus”