PDA

View Full Version : Anh nao oi giup em voi!!!Pls



omai
22-05-2003, 23:34
I am studying in begining course of Linux and over here I point out 2 problems I still confused. Pls help me to solve that or at least give me some hints. Thanx in advanced!!!

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).

2) 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.


Ps: hopefully some Linux experts in this forum can do me a favor
:rolleyes: [COLOR=blue]

Kiem Tam
23-05-2003, 15:26
Nè, em học ngôn ngữ lập trinh nao chưa. Nếu rối thì chỉ cần áp dụng thuật toán vào cấu trúc script của Linux là được chứ gì.
Anh có gửi kèm một tài liệu về script đấy, ráng đọc nha. Em giỏi tiếng anh lắm mà. Chúc em thành công.
Kiem Tam

littlecpu
24-05-2003, 06:23
Hello,

Cái program dưới đây có thể trả lời cho câu hỏi số 1 (problem #1)của bạn. còn câu hỏi số 2 (problem #2) thì bạn thử làm đi, có gì thì post lên trên này, mọi người sẽ giúp cho, ok.


good luck


#!/bin/sh

if (test -f "$1"); then # check to see if the parameter is a file
i=0;
min=9999999;
max=0;
test=0;
var number=0;
total=0;
diff=0;
while read LINE
do
let i=i+1;
let number=$LINE+0
if ( test $min -gt $number); then #if minimum is greater than
let min=$number+0
fi
if ( test $max -lt $number); then
max=$number
fi
let total=$total+$number
done < "$1"
let diff=$max-$min;
let total=$total/$i;
echo "min is $min"
echo "max is $max"
echo "max-min= $diff"
echo "average = $total"
fi

omai
27-05-2003, 17:43
To Kiem Tam :
cam on anh ve cai tutorial do , em cung hoc theo sach online thoi chu dua vao may cai hand out cua thay thi mo tit !!! Anyway ...Dank U wel!!!!

To littlecpu: anh da cuu em 1 ban thua trong thay roi, em bi lam nhom voi 1 con Hl beo, ma no luoi qua..chi di bar thoi. It nhat co bai nay roi thi em chac du pass roi.hic hic...em van dang co gang lam problem 2 kia...neu co y nao hay anh chi em dum nha!!!

Ps: mong ngay hau ta !!! :o[COLOR=royalblue][B][SIZE=3]

littlecpu
03-06-2003, 03:24
Chào bạn,

nếu bạn muốn, bạn có thể post cách làm/ suy nghĩ của bạn lên trên này, mọi người sẽ giúp bạn. Bạn không cần phải viết code đâu, bạn có thể viết dạng pseudocode cũng được.

Good luck

omai
06-06-2003, 00:23
Em viet tam the nay, khong biet co hieu dung cau hoi khong anh nhi? Co gi sua cho em voi vi em thay no chay nhung cu the nao y.

#!/bin/bash

#This script is about search a directory and then within the
#directory then search a string.


#The actual command
# Ask User to input the directory for search

echo Please type the full Directory you want to search,such as /home/itperson/
read dir1
echo your directory is---- $dir1

#Ask User to input the string that he want to search

echo Please type the string you want to search in this directory
read string1

echo you want to search------- $string1
cd $dir1
tree $dir1


echo In file

grep $string1 *



echo is the string $string1 present.

Cam on anh nhieu ( mong tra loi cua anh)
:question: