Posts

Showing posts with the label Unix

Shell script to find factorial of a number using recursion

A shell script is a computer program designed to be run by the Unix shell, a command line interpreter. This blog is about a shell scripting program to find the factorial of a number using recursion. Logic The logic is simple. If the number ' n ' is 1, return 1. Else return ' n ' * ' factorial(n-1) '. Program #!/bin/sh factorial() { if [ "$1" -gt "1" ]; then a=`expr $1 - 1` b=`factorial $a` c=`expr $1 \* $b` echo $c else echo 1 fi } echo "Enter a number:" read x factorial $x Things to note: - After writing the script, change the mod of the script to enable execution. This is done by: chmod +x factorial.sh or chmod 755 factorial.sh Output of the program Enter a number: 4 24 Good to read 1) Java program to convert mobile number pad to characters 2) Difference between "diff" and "sdiff" command 3) Java program to return first non repeated character in a string

Difference between "diff" and "sdiff" commands in Unix

Image
Hi everyone, in this blog post, I will be discussing about the difference between "diff" and "sdiff" commands in Unix. This is my first post about Unix. diff command diff command will compare two files and prints the difference between the 2 files. The format of diff command is diff file1 file2 . sdiff command sdiff command will compare two files side by side. The format of sdiff command is sdiff file1 file2. The contents of files are displayed side by side with a marker denoting the difference between each files. Some of the important markers used in sdiff are as follows: | - denotes the 2 files differ in the line completely. < - only the first file contains the line. > - only the second file contains the line. The better way to depict the difference is by showing examples. Here, I am comparing 2 files which are named as " ipl_teams_2008.txt " and " ipl_teams_2015.txt ". Let's see the contents of the files. ...