Linux Systems - Assignment 21
#!/bin/bash
if [ $# -gt 0 ]
then
if [ -f $1 ]
then
if [ -s $1 ]
then
total_lines=`cat $1 | wc -l`
if [ $total_lines -ge 5 ]
then
echo "Before replacing"
cat $1
percent=$((total_lines/5))
for i in `seq $percent`
do
random_number=`shuf -i 1-$total_lines -n1`
sed -i "$random_number s/.*/<-----------Deleted------------>/" $1
done
echo "After replacing"
cat $1
else
echo "Error: Not enough lines."
fi
else
echo "Error : $1 is empty file. So can’t replace the string."
fi
else
echo "Error : No such a file."
fi
else
echo "Error : Please pass the file name through command line."
fi