PDA

View Full Version : Linux- Challenge ???



omai
03-06-2003, 00:22
:o
[B][COLOR=blue] Xin chao cac anh cac chi trong forum tin hoc nay !!!
Em thuc su rat vui khi tim duoc 1 forum moi nguoi deu nhiet tinh giup do nhau ( dac biet tham gia boi nhung nguoi co nang luc ve IT nhu tren nay)

Em co 2 cau hoi trong 1 assignment: 1 cau em da tu giai duoc nhung chac can su chi giao them cua cac Linux experts tren nay , con cau thu 2 thi dung la chiu chet roi....rat rat mong duoc su chi giao

1)Problem 1:

write a shell script which displays from a text file with numbers (one at each line):
The mininmum
The maximum
Maximum - minimum
The average of all numbers

Do this in normal shell script or take a look at awk (for the awk option it will be the preference).

Solution:
#!/bin/bash



STRING="`cat num`"



set $STRING

k=$#



if [ $1 -ge $2 ]

then

m=$1

n=$2

else

m=$2

n=$1

fi



echo $1

echo $2



let s=$1+$2



shift 2



while [ $1 ]

do

echo $1

if [ $1 -gt $m ]

then

m=$1

fi

if [ $1 -lt $n ]

then

n=$1

fi



let s=$s+$1



shift 1



done





#echo the sum is : $s

#echo the average is :

#echo $s/$k >ave | bc -l ave

#echo the maximal value is : $m

#echo the minimal value is :$n

Problem 2:

Write an interactive script which asks for a directory name and a string to search for in that directory. It then displays for every file in that directory "in file [filename] is the string [String] present/ not present. Note that only in the given directory should be searched not in the subdirectories of it.

Mong duoc su chi giao som cua cac bac tren nay!!!