Index
Question
Q1: Demonstration of filter Q:2 Demonstrate of Redirection operation Q:3 Demonstrate the general purpose utility Q : 4 Write a shell script using command line argument to perform all arithmetic operation. Q5: Demonstrate Use of ace Construct To Display Greeting Message. Q:6 Using for Loop in shell script display multiplication table Q7: Write a interactive shell script to accept a perttern from the user and find it in a text file Q :8 Write a shell script to change extension of files. Q :9 Concatenate and join two user specified file using System call specified File using System Call Q :10 Find the attributes of given file. Q:11 Count the number of characters,line,and words. Q12: Write a shellscript to count number of directories and regulars files in present Working directories Q13: Write a C program using error handling system call to display numbers of error available in the operating system
Sign Remar ks
OUTPUT:
OUTPUT:
OUTPUT:
Q.4) Write a shell script using command line argument to perform all arithmetic operation.
Code:
#!bin/sh echo "The shell script using command line argument to perform all arithmetic operation " if [ $# -ne 2 ] then echo "\n Please enter two number as command line argument\n " else echo "First no. is : $1" echo "Second no. is : $2" echo " " echo "Enter the choice" echo " " echo "Press 1 for Addition" echo "Press 2 for subtraction" echo "Press 3 for Multiplication" echo "Press 4 for Division" printf "\n" read choice case $choice in 1) a=$(($1+$2)) echo " " echo "Addition is: $a";; 2) a=$(($1-$2)) echo " " echo "Subtration is: $a";; 3) a=$(($1*$2)) echo " " echo "Multiplication is: $a";; 4) a=$(($1/$2)) echo " " echo "Division is: $a";; *) echo "Wrong choice";; esac fi
OUTPUT
OUTPUT:
OUTPUT:
Q.7 )Write a interactive shell script to accept a parttern from the user and find it in a text file
Code:
#!bin/sh echo "Enter the patter u want to matched: " echo " " read pat if grep "$pat" abc.txt then echo "Pattern is Found" else echo "Pattern is not Found" fi echo " "
OUTPUT:
Q.9) Concatenate and join two user specified file using System call specified File using System Call
Code:
#include<stdio.h> #include<fcntl.h> #include<sys/stat.h> int main() { int fd1=open("./xyz.txt", O_RDONLY); int fd2=open("./abc.txt", O_RDONLY); int fd3=open("./concate.txt",O_WRONLY | O_CREAT,0666); int s1,s2,i; char ch,a='\n'; s1 =lseek(fd1,-1,SEEK_END); lseek(fd1,0,SEEK_SET); s2 =lseek(fd2,-1,SEEK_END); lseek(fd2,0,SEEK_SET); for(i=1;i<=s1;i++) { read(fd1,&ch,1); write(fd3,&ch,1); printf("%c",ch); } lseek(fd3,0,SEEK_END); write(fd3,&a,1); for(i=1;i<=s2;i++) { read(fd2,&ch,1); write(fd3,&ch,1); printf("%c",ch); } }
OUTPUT
OUTPUT :
Code:
#include<stdio.h> #include<fcntl.h> void main() { int fd,char1=0,words=0,lines=0; char a; fd=open("./a1.txt",O_RDONLY); if(fd==-1) { perror("file a1.txt"); } else { while(read(fd,&a,1)>0) { if(a==' '||a=='\n') { words++; } if(a=='\n') { lines++; } char1++; printf("%c",a); } printf("\nThe number of characters=%d\n",char1); printf("\nThe number of words=%d\n",words); printf("\nThe number of lines%d\n",lines); } close(fd); }
OUTPUT :
Q.12) Write a shellscript to count number of directories and regulars files in present Working directories Code:
#!bin/sh echo "The shell script to count number of directories and regular file in present working directory" numberofdir=0 numberoffile=0 for f1 in * do if test -e $f1 then if test -d $f1 then numberofdir=$(($numberofdir+1)) else numberoffile=$(($numberoffile+1)) fi fi done echo "Number of files =$numberoffile" echo "Number of directory=$numberofdir" echo "\n Directories and files are given bellow :" ls -l exit 0
OUTPUT :
Q.13) C program using error Handling system calls to display no. Of error available in operation system
Code: #include<stdio.h> int main() { int i; for(i=0;i<135;i++) { printf("\n%d:\t%s",i,strerror(i)); } }
OUTPUT :
OUTPUT :