分类: LINUX
2018-03-17 13:54:56
#!/bin/bash
##
printf "the man is:\n"
while read line
do
number=$(echo ${line} | awk '{print $1}')
name=$(echo ${line} | awk '{print $2}')
birthday=$(echo ${line} | awk '{print $3}')
gender=$(echo ${line} | awk '{print $4}')
if [ "${gender}" == "man" ];then
printf "${name}\t ${birthday}\n"
fi
done < $1
##
_num_=5000
printf "the number less 5000 is:"
while read line
do
number=$(echo ${line} | awk '{print $1}')
name=$(echo ${line} | awk '{print $2}')
birthday=$(echo ${line} | awk '{print $3}')
gender=$(echo ${line} | awk '{print $4}')
if [ "${number}" -lt "${_num_}" ];then
printf "${name}\t ${birthday}\n"
fi
done < $1
执行结果:
tay@tay:/mnt/hgfs/hzs/shell$ cat a.txt
number name birthday gender
1234 zhangsan 19911212 man
4567 lisi 20011212 woman
5214 wangmazi 20411012 man
4574 jia 20320101 woman
1456 yan 20000101 woman
tay@tay:/mnt/hgfs/hzs/shell$ ./parase_file.sh a.txt
the man is:
zhangsan 19911212
wangmazi 20411012
the number less 5000 is:./parase_file.sh: 第 28 行: [: number: 期待整数表达式
zhangsan 19911212
lisi 20011212
jia 20320101
yan 20000101
tay@tay:/mnt/hgfs/hzs/shell$