Ignou MCSL 45
Ignou MCSL 45
Ignou MCSL 45
The grep filter searches a file for a particular pattern of characters, and displays
all lines that contain that pattern. The pattern that is searched in the file is
referred to as the regular expression.
Syntax :
Example :
Syntax :
Example :
sort -r Index.txt
(c) To count the no. of characters and words in a given text file.
Answer : - wc command is used to find out number of lines, words and
characters present in the files specified in the file arguments.
By default it displays four-columnar output. First column shows number of
lines present in a file specified, second column shows number of words present
in the file, third column shows number of characters present in file and fourth
column itself is the file name which are given as argument.
Syntax :
wc [options] [files]
Example :
wc Test.txt
wc Data.txt Index.txt
wc -c Test.txt
wc -w Test.txt
cat command is used to immediately add some text to your new file.
Type the following command at the terminal prompt and then press Enter :
After pressing Enter, you are not returned to the terminal prompt. Instead, the
cursor is placed on the next line, and you can start entering text directly into
your file. Type your lines of text, pressing Enter after each line. When you are
done, press Ctrl+D to exit the file and return to the prompt.
touch myfile.txt
touch Test.txt Demo.txt
vi myfile.txt
[After pressing Enter, press i to insert new text into the file. Press ESC and then
press :x to save the file].
(e) Change the file permissions to Read, Write and Execute for
everyone on a data file created by you.
Answer : - To change file and directory permissions, use the command chmod
(change mode). The owner of a file can change the permissions for user (u),
group (g), or others (o) by adding (+) or subtracting (-) the read, write, and
execute permissions.
There are two basic ways of using chmod to change file permissions: The
symbolic method and the absolute form.
Symbolic Method
Example :
Absolute Form - The other way to use the chmod command is the absolute form,
in which you specify a set of three numbers that together determine all the
access classes and types. Rather than being able to change only particular
attributes, you must specify the entire state of the file's permissions.
The three numbers are specified in the order : user (or owner), group, and
other. Each number is the sum of values that specify read, write, and execute
access :
Permission Number
Read (r) 4
Write (w) 2
Execute (x) 1
Example :
1. Hard Links
2. Soft Link or Symbolic links
Hard Links - Users are not allowed to create hard links for directories. This
might transform the directory tree into a graph with cycles, thus making it
impossible to locate a file according to its name.
Links can be created only among files included in the same filesystem.
Syntax :
ln Demo.txt Test.txt
(g) Compare two text files and display the first difference.
Answer : -
Syntax :
Example :
Syntax :
Example :
"diff" command - This command is used to compare two files line by line.
Syntax :
Example :
Syntax :
du [options] [directories and/or files]
Example :
du /shell/Test.txt
du -h /shell
Syntax :
Replace "filename" with the name of the large file you wish to split. Replace
"prefix" with the name you wish to give the small output files. You can exclude
[options], or replace it with either of the following :
Example :
Syntax :
Example :
chown Debabrata Demo.txt
Q2. (a) Write a shell program to count and print the no. of
positive and negative integers in a list of integers given as input
by the user.
Answer : -echo "How many numbers you want to take input... "
read n
p_no=0
n_no=0
for((i=0;i<n;i++))
do
read a[$i]
then
p_no=`expr $p_no + 1`
else
n_no=`expr $n_no + 1`
fi
done
10
-60
45
92
-56
read file1
read file2
if test -w $file1
then
if test -r $file2
then
do
else
fi
else
fi
Output
/shell/Index.txt
Q2. (c) Write a shell script to display the no. of times the given
pattern occurs in a .dat file and display the count.
Answer : -
echo "Enter the pattern..."
read pattern
file="/shell/a.dat"
patternLen=${#pattern}
count=0
do
line=`echo ${line}`
len=${#line}
start=1
end=$patternLen
do
if [ "$s" = "$pattern" ]
then
count=`expr $count + 1`
fi
start=`expr $start + 1`
end=`expr $end + 1`
done
Output
Enter the pattern...
name is
Pattern Occurs = 2
My name is Debabrata
SQL> COMMIT;
Connected.
SQL>
SQL> CREATE TABLE sells (shop_id INT NOT NULL, p_code VARCHAR2(10)
NOT NULL);
SQL> CREATE TABLE bill_master (bill_no INT, bill_amount INT NOT NULL,
bill_date DATE NOT NULL, shop_id INT NOT NULL, cust_id VARCHAR2(10) NOT
NULL, PRIMARY KEY(bill_no));
(iv) Create a view of the items for the manager showing overall
performance of the week for each Brand and Model of the mobile
phones.
Answer : - CREATE OR REPLACE VIEW performance AS SELECT
product.p_code, brand, model, bill_master.bill_no, bill_date, shop_id, cust_id
FROM product, bill_master, bill_details WHERE
bill_master.bill_no=bill_details.bill_no AND bill_details.p_code=product.p_code;
price_update_alert.sql
SQL> @ File_Location\File_name;
Example -
SQL> @ D:\Oracle\price_update_alert.sql;
insert_alert.sql
delete_alert.sql
CREATE OR REPLACE TRIGGER delete_alert
AFTER DELETE ON product
FOR EACH ROW
BEGIN
dbms_output.put_line('Product Code - ' || :OLD.p_code);
dbms_output.put_line('Brand - ' || :OLD.brand);
dbms_output.put_line('Model - ' || :OLD.model);
dbms_output.put_line('Price - ' || :OLD.unit_price);
END;
/
(e) Create a transaction that finds the total items sold per week
and prints the overall revenue generated.
Answer : -
transaction_details.sql
SQL> @ File_Location\File_name;
Example -
SQL> @ D:\Oracle\transaction_details.sql;
To display the output of a procedure in oracle use the following command at
once -
Example -
(g) Create two different types of users: the first user – a manager
who can see reports and change the items and its price value and
second user (a salesperson) who sells these items.
Answer : - Solve it Yourself