postheadericon Write a shell script to check whether the named user is currently logged in or not.


File Name : ex16.sh


clear
echo "Enter user name : \c"
read unm
unm1=$(who | cut -d " " -f 1)
if [ "$unm" = "$unm1" ]
then
            echo " [ $unm ] is already Login"
else
            echo " [ $unm ] is not Login"
fi


postheadericon Write a script which reads a text file and output key attribute of file


Write a script which reads a text file and output the following 
1). Count of character, words and lines.
2). File in reverse.
3). Frequency of particular word in the file.
4). Lower case letter in place of upper case letter.

File Name : ex15.sh


echo "Enter File Name \c"
read fname
choice=y
while [ "$choice" = "y" ]
do
echo " ------------------------------------"
echo " 1. Count character,words and lines"
echo " 2. Reverse File"
echo " 3. Found frequency of word"
echo " 4. Convert upper to lower"
echo " 5. Convert lower to upper"
echo " 6. Exit
echo " ------------------------------------"
echo "Enter Choice: \c"
read ch
case $ch in
1)
        echo "Total Characters:\c"
        wc -c $fname
        echo "Total Words:\c"
        wc -w $fname
        echo "Total Lines:\c"
        wc -l $fname
        ;;
2)
        rev $fname
        ;;
3)
        echo "Find your word :\c"
       read w
        echo "Frequency:\c"
        grep  -c "$w" $fname
        ;;
4)
        echo "Enter Text : \c"
        read text
        echo $text | tr "[A-Z]" "[a-z]"
        ;;
5)
        echo "Enter Text : \c"
        read text
        echo $text | tr "[a-z]" "[A-Z]"
        ;;

6)         exit
            ;;

*)         echo "Invalid Choice ....."
                        ;;
            esac
 echo "Do u want to continue.....? [y/n]"
 read choice
 case $choice in
  Y|y) choice=y;;
  N|n) choice=n;;
  *) choice=y;;
 esac
done

postheadericon Write a script to make following file and directory management operations


14.  Write a script to make following file and directory management operations menu based:
           Display current directory
           List directory
           Make directory
           Change directory
           Copy a file
           Rename a file
           Delete a file
           Edit a file

File Name : ex14.sh


clear
choice=y
while [ "$choice" = "y" ]
do
echo "____________________________________"
echo "          MAIN MENU       "
echo "____________________________________"
echo "1 - DISPLAY CURRENT DIRECTORY"
echo "2 - LIST DIRECTORY"
echo "3 - MAKE DIRECTORY"
echo "4 - CHANGE DIRECTORY"
echo "5 - COPY A FILE"
echo "6 - RENAME A FILE"
echo "7 - DELETE A FILE"
echo "8 - EDIT A FILE"
echo "9 - EXIT"
echo "____________________________________"

echo "ENTER THE CHOICE :- "
read choice
case $choice in

            1)         pwd;;

            2)         ls -l;;

            3)        echo "Enter Directory Name "
                       read dir_name
                       mkdir $dir_name
                       echo "[ $dir_name ] Sucessfully Created Directory"
                       ;;

            4)         echo "Enter the Absolute Path to change the directory: "
                        read apath
                        cd $apath
                        echo "Working path changed successfully!"
                        pwd
                        ;;

            5)         echo "Enter name of file: "
                        read filename
                        echo "Copy where? "
                        read apath
                        cp $filename $apath
                        echo "File $filename copied successfully to $apath"
                        ;;

            6)         echo "Enter Current File Name: "
                        read oname
                        echo "Enter New File Name: "
                        read nname
                        mv $oname $nname
                        ;;

            7)         echo "Enter file Name : "
                        read fdel
                        if [ -f $fdel ]; then
                            rm -i $fdel
                        fi
                        ;;

            8)         echo "Enter filename to open it in Text Editor: "
                        read filename
                        cat $filename
                        cat >> $filename
                        #vi $filename
                        ;;

            9)         exit
                        ;;

            *)         echo "Invalid Choice ....."
                        ;;
            esac
 echo "Do u want to continue.....? [ y / n ]"
 read choice
 case $choice in
  Y|y) choice=y;;
  N|n) choice=n;;
  *) choice=y;;
 esac
done

postheadericon Write a shell script to add the statement #include at the beginning of every C source file in current directory containing printf and fprintf.


clear

grep -l -e "printf" -e "fprintf"  *.c > temp.txt

#grep
#    -l, --files-with-matches
#              Suppress normal output; instead print the  name  of  each  input
#           file  from  which  output would normally have been printed.

#    -e PATTERN, --regexp=PATTERN
#             Use PATTERN as  the  pattern.   This  can  be  used  to  specify
#          multiple search patterns


for i in `cat temp.txt`
do  
     sed '1i\#include<stdio .h=".h">' $i &gt; temp2.txt
    cat temp2.txt &gt; $i
    echo "Successfully Added..."
done

# sed i  :
#     -i[SUFFIX], --in-place[=SUFFIX]
#              edit files in place (makes backup if extension supplied)


# sed l  :
#     -l N, --line-length=N
#              specify the desired line-wrap length for the `l' command
</stdio>

postheadericon Write a script to implement the following commands:Tree (of DOS) which (of UNIX)


Tree (of DOS)

echo
if [ "$1" != "" ]  #if parameter exists, use as base folder
   then cd "$1"
   fi
pwd
ls -R | grep ":$" |   \
   sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep "/" | wc -l` = 0 ]   # check if no folders
   then echo "   -&gt; no sub-directories"
   fi
echo
exit

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.