Bash
Exercises – 9
41.
Print Partition: |
`rm -rf file file1`
`rm -rf file.log`
df -h | sort -rnk5 | awk '{print $5,$6}' | sed '$d' > file
df -h | sort -rnk5 | awk '{print $5,$6}' | awk 'BEGIN { FS="%" } { print $1 }'| sed '$d' > file1
rm -f file.log
a=0
for i in `cat file1`
do
a=$(($a+1))
if [ $i -ge 70 ]
then
##echo `sed -n ''$a'p' file | awk '{print $2}'`
`sed -n ''$a'p' file >> file.log`
#echo `sed -n ''$a'p' file `
fi
done
cat file.log
`rm -rf file.log`
df -h | sort -rnk5 | awk '{print $5,$6}' | sed '$d' > file
df -h | sort -rnk5 | awk '{print $5,$6}' | awk 'BEGIN { FS="%" } { print $1 }'| sed '$d' > file1
rm -f file.log
a=0
for i in `cat file1`
do
a=$(($a+1))
if [ $i -ge 70 ]
then
##echo `sed -n ''$a'p' file | awk '{print $2}'`
`sed -n ''$a'p' file >> file.log`
#echo `sed -n ''$a'p' file `
fi
done
cat file.log
42.
Read 1: |
dialog --inputbox
"Enter String1" 20 30
read string1
dialog --inputbox "Enter String2" 20 30
read string2
if [ $string1 = $string2 ] ; then
dialog --inputbox "The string entered is: $string1" 20 30
else
dialog --inputbox "The string entered is :$string2" 20 30
fi
read string1
dialog --inputbox "Enter String2" 20 30
read string2
if [ $string1 = $string2 ] ; then
dialog --inputbox "The string entered is: $string1" 20 30
else
dialog --inputbox "The string entered is :$string2" 20 30
fi
43.
Read 2: |
cat
file1 |
while read line
do
echo "{$line}"
# last=$line
done
printf "\nAll done, last:$last\n"
exit 0 # End of code.
while read line
do
echo "{$line}"
# last=$line
done
printf "\nAll done, last:$last\n"
exit 0 # End of code.
44.
Rev: |
#!/bin/bash
echo "enter a number"
read num
while [ $num -ne 0 ]
do
rev=$(($num % 10))
num=$(($num / 10))
echo -n "$rev"
done
echo "enter a number"
read num
while [ $num -ne 0 ]
do
rev=$(($num % 10))
num=$(($num / 10))
echo -n "$rev"
done
45.
Sed: |
#!/bin/bash
# This is a simple script that removes blank lines from a file.
# No argument checking.
#
# You might wish to add something like:
#
E_NOARGS=65
if [ -z "$1" ]
then
echo "Usage: `basename $0` target-file"
exit $E_NOARGS
fi
# Same as
# sed -e '/^$/d' filename
# invoked from the command line.
sed -e /^$/d "$1"
# The '-e' means an "editing" command follows (optional here).
# '^' is the beginning of line, '$' is the end.
# This match lines with nothing between the beginning and the end,
#+ blank lines.
# The 'd' is the delete command.
# Quoting the command-line arg permits
#+ whitespace and special characters in the filename.
# Note that this script doesn't actually change the target file.
# If you need to do that, redirect its output.
exit 0
# This is a simple script that removes blank lines from a file.
# No argument checking.
#
# You might wish to add something like:
#
E_NOARGS=65
if [ -z "$1" ]
then
echo "Usage: `basename $0` target-file"
exit $E_NOARGS
fi
# Same as
# sed -e '/^$/d' filename
# invoked from the command line.
sed -e /^$/d "$1"
# The '-e' means an "editing" command follows (optional here).
# '^' is the beginning of line, '$' is the end.
# This match lines with nothing between the beginning and the end,
#+ blank lines.
# The 'd' is the delete command.
# Quoting the command-line arg permits
#+ whitespace and special characters in the filename.
# Note that this script doesn't actually change the target file.
# If you need to do that, redirect its output.
exit 0
No comments :
Post a Comment