#判断文件并计算单词
#!/bin/bash
if [ $# -ne 2 ]
then 
	echo "请输入两个参数,第一个是目录名字,第二个是单词"
	exit
fi

cd $1
for f in `ls .`
do 
	if [ -d $f ]
	then
		if [ -f $f/test.txt ]
		then
			n=`grep -cw "$2" $f/test.txt`
			echo "$1/$f目录下面有test.txt,test.txt里面的$2有$n个$2."
		fi
	fi
done

#打印正方形
#!/bin/bash
while:
do
	read -p "Please input a number:" n
	n1=`echo $n|sed 's/[0-9]//g'`
	if [ -n "$n1" ]
	then
		echo "$n is not a number,please input a number."
		continue
	else
		break
	fi
done

for i in `seq 1 $n`
do
	for j in `seq 1 $n`
	do
		echo -n "■ "
	done
	echo
done


#问候用户
#!/bin/bash

cat /etc/passwd |while read line
do
	username=`echo $line|awk -F ':' '{print $1}'`
	uid=`echo $line|awk -F ':' '{print $3}'`
	echo "Hello,$username, your uid is $3."
done

#格式化输出 xml
#!/bin/bash
sed '/<!--.*-->/d' test.xml > test2.xml
egrep -n '<!--|\-\->' test2.xml |awk -f ':' '{print $1}' > /tmp/line_number1.txt
n=`wc -l /tmp/line_number1.txt |awk '{print $1}'`
n1=$[$n/2]
for i in `seq 1 $n1`
do
	j=$[$i*2]
	k=$[$j-1]
	x=`sed -n "$k"p /tmp/line_number1.txt`
	y=`sed -n "$j"p /tmp/line_number1.txt`
	sed -i "$x,$y"d test2.xml
done

grep -n 'artifactItem>' test2.xml |awk '{print $1}' |sed 's/://' > /tmp/line_number2.txt
n2=`wc -l /tmp/line_number2.txt|awk '{print $1}'`

get_value()
{
	sed -n "$1,$2"p test2.xml |awk -F '<' '{print $2}'|awk -F '>' '{print $1,$2}' > /tmp/value.txt
	cat /tmp/value.txt|while read line
	do
		x=`echo $line|awk '{print $1'}`
		x=`echo $line|awk '{print $2'}`
		echo artifactItem:$x:$y
	done
}
n3=$[$n2/2]
for j in `seq 1 $n3`
do
	m1=$[$j*2-1]
	m2=$[$j*2]
	nu1=`sed -n "$m1"p /tmp/line_number2.txt`
	nu2=`sed -n "$m2"p /tmp/line_number2.txt`
	nu3=$[$nu1+1]
	nu4=$[$nu2-1]
	get_value $nu3 $nu4
done

#小函数
#!/bin/bash
f_judge()
{
	if [ -d /home/log ]
	then
		find /home -name "tmp*" -exec mv {} /home/log/ \;
	else
		mkdir /home/log
		exit
	fi
}

f_judge