Assignment Using VI-EDITOR Do The Following Exercise: Assignment-Linux Class - Bca Ii YEAR (2016-17)
Assignment Using VI-EDITOR Do The Following Exercise: Assignment-Linux Class - Bca Ii YEAR (2016-17)
ASSIGNMENT
Coding:-
3. Open two files ‘txtfile’ and ‘newfile’ and copy/cut 5 lines from
txtfile and paste them in newfile using vi-editor.
Coding:-
5. Create macro
i. To paste your name at any position in the file
Coding:-
To create the macro use the following ex mode command:
:map M bhawana
WRITE COMMANDS
i. List all files that match a class.
Coding:-
Use the following command:
$ grep –l “[aA]c[tT]iv” *.*
Coding:-
echo
tput clear
echo
echo “Current Users:
$who –Hu
echo
Output:-
ii. List all files in current directory and save the list in a file ABC.
Also save the contents of the files in ABC and display the contents in
ABC in sorted order.
Coding:-
echo
tput clear
echo
ls | cat>ABC
sort | cat ABC
echo
Output:-
Output:-
iv. To save current date and time, number of files & directories in the
current directory and contents of all the files to a single file NFL.
Coding:-
tput clear
echo Today’s date is : `/bin/date`>Nfl
echo Number of file in current directory is : `/bin/ls|we –l`>>Nfl
for x in `/bin/ls`
do
if [ -f $x ]; then
echo $x>>Nfl
cat $x>>Nfl
fi
done
Output:-
Output:-
Coding:-
tput clear
echo “ Enter the file name: “
read file
if [ !-e$file ] ; then
echo “File does not exit!!”
elif [ -d$file ] ; then
echo “It is a directory.”
elif [ -f$file ] ; then
echo “It is a regular file”
else
echo “It is of other type”
fi
Output:-
Output:-
Output:-
Output:-
Coding:-
echo
echo
tput clear
echo
echo
who –Hu
until [ who | grep “BCA2” ]
do
sleep 30
done
echo “ $ just logged in ”
echo
Output:-
xi. To save current date & time, number of files in the current
directory and contents of all the files matching a pattern to a single file
NPFL.
Coding:-
echo
echo
echo today’s date is `date`>NPEL
echo number of files in the directory is `ls|wc –l` >>NPEL
grep –l ‘for’ `ls`>l
for x in `cat l`
do
cat $x>>NPEL
done
echo
echo
Output:-
Output:-
Coding:-
tput clear
echo “ `date +%D` “
echo “ `date +%A` “
case “ `date +%u` ” in
1|3) echo “It is sunny day”;;
2|4) echo “It is rainy day”;;
5|6) echo “It is cool day”;;
*) echo “It is weekend”
Esac
Output:-
xiv. To accept a string from the terminal and echo a suitable message if
it doesn’t have at least 9 characters.
Coding:-
echo
echo
tput clear
echo
echo
echo “Enter any String”
read str
if [ `exp $str : ‘.*’` -lt 9 ] ; then
echo “You must enter string having least 9 characters”
else
echo “Your string is accepted”
fi
echo
AUTHOR NAME- YASHWANT KUMAR Page 17
ASSIGNMENT- LINUX CLASS- BCA IInd YEAR [2016-17]
echo
Output:-
xvi. Write a shell script to swap two numbers using third variable.
Coding:-
tput clear
echo “Program for swapping two numbers”
echo “Enter 1st number:”
read a
echo “Enter 2nd number:”
read b
let t=$a
let a=$b
let b=$t
echo “Swapped numbers are”
echo “1st number:” $a
echo “2nd number:” $b
Output:-
Coding:-
Echo “enter the no. upto which you want prime no.”
Read n
For(( i=1; i<=n; i++))
Do
Flag=0
For((j=2;j<i; j++))
Do
If[`expr $i % $j` -eq 0]; then
Flag=1
Fi
Done
If [$flag –eq 0 ]
Then
Echo $i
Fi
Done
Output:-
Output:-
xix. Write a shell script to sort the content of a file XYZ and save it in
BCAII.
Coding:-
Echo “enter the content to be searched:\c”
Read content
Echo “enter file to be searched:\c”
Read flname
Echo “searching for $content from file $flname”
Grep “$content” $flname
Output:-
Coding:-
tput clear
echo “Enter any number: “
read num
let n=1
while [ $n –ne 11 ]
do
let i=num*$n
echo “$num * $n = $i”
let n=n+1
done
Output:-