1. Write a shell script in Linux to shift all characters in a
file forward by five characters. (Thus “a” becomes “f’”)?
cat file.txt|tr [a-z A_Z} [f-za-e F_ZA-E]
2. ODD or EvEn
echo "Enter the Number"
read a
b=`echo "$a % 2"|bc`
if [ $b -eq 0 ]
then
echo "Given Number is Even "
exit
fi
echo " Given Number is odd"
3.write a shell script that counts a number of unique word contained in the file and print them in alphabetical order line by line?
Make ' ' to '\n' then pipe to sort|uniq.
#!/bin/csh
# Here tr -s ' ' replaces all multiple ' ' with single ' '
# next pipe the above stream to replace each ' ' with '\n'
# next pipe the above stream to get a sorted list of words
# then pipe the unique words to outfile
tr -s ' ' < $1 | tr ' ' '\n' | sort | uniq > $1.out
4. how to convert a string to int???
To increment
echo enter the string
read str
str=`expr $str + 1`
echo $str
for integer
declare following in your script
typeset -i str
5.string reverse using shell scripts:
6.Shift Command in Command Line argts:
What is the use of "shift" command in passing parameters?
"shift" is useful when you need to access positional
parameters more than 9.
EX- execute a script to display 11th position parameter.
#./test.sh 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th
12th
ex:
withen the script write "shift 2" before "echo $9"to
display 11th parameter.
withen the script write "shift 3" before "echo $9"to
display 12th parameter.
7.What do u mean by $#,$* in unix programming?
$# The number of command line argument
$* All the arguments on the command lin
8. Grep,e-grep [ grep extended with Regular Expressions ]
Grep Man Page
9. How to modify the PATH variable and make it executable?
we can set PATH by using export PATH command.
ex:-
PATH=/opt/j2sdk1.4.2_04/bin:............
export PATH
and to make it executable we can set the same
in ".bash_profile".
To execute it ". .bash_profile"
2)
setenv PATH "/workingdir/"
10. Linux Shell Scripting Beginner Tutorial:
Click here
No comments:
Post a Comment