java1-26
java1-26
b.
echo "Enter the first number:"
read num1
# Ask the user to enter the second number
echo "Enter the second number:"
read num2
# Add the two numbers
mul=$((num1 * num2))
# Print the multiplication
echo "The multiplication of $num1 and $num2 is $mul."
grep
The grep command searches a file or files for lines that match
a provided regular
expression (“grep” comes from a command meaning to globally
search for a regular
expression and then print the found matches).
Syntax: grep [options] regular expression [files]
To exit this command, type 0 if lines have matched, 1 if no
lines match, and 2 for
errors. This is very useful if you need to match things in
several files. If you wanted to
find out which files in our vvsdirectory contained the word
“mca” you could use grep
to search the directory and match those files with that word.
All that you have to do is
give the command as shown:
grep ‘mca’ /vvs/*
The * used in this example is called a meta-character, and it
represents matching zero
or more of the preceding characters. In this example, it is
used to mean “all files and
directories in this directory”. So, grep will search all the
files and directories in vvsand
tell you which files contain “mca”.
b.
#!/bin/bash
echo "Enter a number: "
read num
fact=1
for ((i=1;i<=num;i++))
do
fact=$((fact*i))
done
echo "Factorial of $num is $fact"
b.
#!/bin/bash
echo "Enter a decimal number:"
read decima
# convert decimal to hexadecimal
hex=$(echo "obase=16; $decimal" | bc)
echo "The hexadecimal equivalent of $decimal is $hex."
b.
In file,
$ cat file
Unix is an OS
Linux is also Unix
Welcome to Unix, and Unix OS.
In Terminal
$ grep -o ‘Unix’ file | wc -l
OR
grep -i -o word filename.txt | wc -l
Examples:
$chmodu-wx student
Removes write and execute permission for users
$ch modu+rw,g+rwstudent
b.
BEGIN{}
{
print len=length($0),"\t",$0
wordcount+=NF
chrcnt+=len
}
END {
print "total characters",chrcnt
print "Number of Lines are",NR
print "No of Words count:",wordcount
}
b.
echo "Enter file name"
read file
awk '$0!~/[aeiou]/{ count++ }
END{print "The number of lines that does not contain vowels
are: ",count}' $file
b.
read a
read b
sum=$(( $a + $b ))
echo "Sum is: $sum"
b.
echo "Enter numbers to find their average (space-separated): "
read -a nums
sum=0
for i in "${nums[@]}"
do
sum=$((sum + i))
done
avg=$((sum / ${#nums[@]}))
echo "The average is: $avg"
b.
grp -i -o word filename.txt | wc -l
24 A. Explain chmod , useradd command with example. B. write
an awk script to find the no of characters, words and lines in
a file.
a.
chmod–used to change the permissions of a file or directory.
Examples:
$chmodu-wx student
Removes write and execute permission for users
$ch modu+rw,g+rwstudent
b.
BEGIN{}
{
print len=length($0),"\t",$0
wordcount+=NF
chrcnt+=len
}
END {
print "total characters",chrcnt
print "Number of Lines are",NR
print "No of Words count:",wordcount
}