- What is an interval regular expression (IRE)? Give an example of IRE.
Ans: 1) An IRE is an expression that uses the characters { and } with a
single or pair of numbers between them.
2) ch\(m\) - Here, the metacharacter ch can occur m times.
a\{5,10\}
- What is the sed command? Describe the format of the sed
command.
Give an example.
Ans: 1) sed is a multipurpose tool which combines the work of several
filters.
2) sed options 'address action' file(s)
3) sed -n '1,$s/Basic/Java/g' foo
- Frame regular expressions to match lines containing
(i) jefferies jeffery jeffeys
(ii) hitchen hitchin hitching
(iii) dix dicks dickson dixon.
Ans: (i) jeffe*r*[iy]e*s* (ii) hitch[ei]ng* (iii) di[xc]k*s*o*n*
- sum and n are two variables with numeric values.
Write a script to calculate
sum / n with two digital precision after the decimal point.
Ans: echo "scale=2; $sum / $n" | bc
- Write a script to read in a number n as an argument and calculate its
factorial n!
where n! = n x (n - 1) x (n - 2) x .... x 1.
Ans: #!/bin/sh
n=$1
fac=$1
while [ $n -gt 1 ]
do
n=`expr $n - 1`
fac=`expr $fac \* $n`
done
echo "$1! = $fac."