Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Script:
#! /bin/sh
sed -n $2,$3p $1
Write a Shell script that deletes all lines containing a specified word in one or more files supplied as arguments to it.
Script:
#!/bin/bash
word="$1"
let paracount=$#-1
let counter=1
while (( $paracount >= $counter)); do
let counter+=1
shift 1
sed -i "/$word/d" $1
done
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Script:
#!/bin/bash
for i in `ls`; {
if [[ -r $i ]]&&[[ -w $i ]]&&[[ -x $i ]];
then echo $i;
fi;}
Write a Shell script that receives any number of file names as arguments checks if every argument supplied is a file or a directory and reports accordingly. Whenever the argument is a file, the number of lines on it is also reported.
Script:
#!/bin/bash
echo $1
let paracount=$#
let counter=1
while (( $paracount >= $counter )); do
let counter+=1
shift 1
if [ -d $value ];
then echo $value--directory;
fi
if [ -f $value ];
then echo $value--file;
awk 'END{print NR}' $value;
fi
done
Write a Shell script that accepts a list of file names as its arguments, counts and reports the occurrence of each word that is present in the first argument file on other argument files.
Script:
#!/bin/bash
declare -A word_list
for word in `cat $1|sed 's/[,.:;/!?()_{}+-=*]/ /g'`
do
word_list[$word]=0
done
shift 1
for file in $*
do
for word in `cat $1|sed 's/[,.:;/!?()_{}+-=*]/ /g'`
do
for key in ${!word_list[\*]}
do
if [[ $word =~ $key ]]; then
word_list[$key]=$((${word_list[$key]}+1))
fi
done
done
done
for key in ${!word_list[*]}
do
echo $key": "${word_list[$key]}
done
Write a Shell script to list all of the directory files in a directory.
Script:
#!/bin/bash
judge( ){
for i in `ls`; {
if [ -d $i ];
then echo $i--directory;
cd $i;
judge
fi;}
cd ..
}
judge
Write a Shell script to find factorial of a given integer.
Script:
#!/bin/bash
num=$1
[ $? -ne 0 ] && echo "please input a number" && exit 1
[ $# -ne 1 ] && echo 'please input a number' && exit 1
[ $num -le 0 ] && echo "please input a number bigger than 0" && exit 2
s=1
for i in `seq 1 $num`
do
s=$(($s*$i))
done
echo $s
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.Script:#! /bin/shsed -n $2,$3p $1Write a ...