Untitled Document
Flavours Of Unix Commands
1. Program - To do calculation using bc command Click Here
       #!/bin/ksh 
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Program To do calculation using bc command 
       
       echo " Enter Any two Number "
       read num1
       read num2 
              
       sum=`echo $num1 + $num2 | bc` 
       echo " Sum of two Number $num1 + $num2 is : $sum "
       
2. Program - To print contains of file from given line number to next given number of lines. Click Here
       #!/bin/ksh 
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Program To print contains of file from given line number to next given number of lines
       
      if [ $# -eq 0 ] 
then
    echo "$0:Error command arguments missing!"
    echo "Usage: $0 start_line   uptoline   filename"
    echo "Where start_line is line number from which you would like to print file"
    echo "uptoline is line number upto which would like to print"
    echo "For eg. $0 3 15 myfile"
    echo "Here from myfile total 13 lines printed starting from line no. 3 to"
    echo "line no 15."
    exit 1
fi

#
# Look for sufficent arg's
#

    if [ $# -eq 3 ]; then
	if [ -e $3 ]; then
    	    tail +$1 $3 | head -n$2
         else
    	    echo "$0: Error opening file $3" 
	    exit 2
	fi   
    else
        echo "Missing arguments!"	
    fi
       
3. Program - To Print table of value(number) entered through keyboard Click Here
       #!/bin/ksh 
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Program To Print Table of Any Number
       
       echo " Enter Any Number "
       read num 
             
       x=1
       
       for ((i=1 ; i<=10 ; i++ ))
              {
                let x=$num * $i
                echo " $num * $i is = $x "
               } 
       
       
4. Program - To Print nos as 5,4,3,2,1 using while loop Click Here
       #!/bin/ksh 
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Program To Print Table of Any Number
       
          i=5 

         while test $i != 0
         do
	       echo "$i"
	       i=`expr $i - 1` 
         done 
      
5. Program - To read a file using while loop Click Here
       #!/bin/ksh 
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # To read a file using while loop
       
          
          if [[ $# -lt 1 ]]; then
            echo " ----- $0 Usage -----"
            echo " Please Provide a file name with full path e.g m/man/mangesh/lenovo/emp.csv"
            echo "---------------------"
            exit 1
          
           else 
             while read line 
             do 
             echo "$line"
             done < $1 
             fi
                  
      
6. Program - To search a word from a file and print its status Click Here
       #!/bin/ksh 
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Program - To search a word from a file and print its status
       
          
          if [[ $# -lt 2 ]]; then 
              
              echo "###### $0 USGAE ######"
              echo " 1. Please provide a word to be searched "
              echo " 2. Please provide a filename "
              echo "######################"
              exit 1
          fi
              
                 if [[ -f $2 ]]; then 
                  search=`grep "$1" "$2"`
                     
                      if [[ $? -eq 0 ]]; then 
                         echo "###### Lines Found ######"
                      else 
                         echo "###### No Records Found !! ######"
                      fi
                  
                  else    
                   echo "File Not Found"
                  fi 

      
Untitled Document