#!/bin/sh
#$0 是脚本的名字 $1是第一个参数,$2是第二个参数,$#是参数的个数
if [ $1 == "-race" ]
then
type=1
elif [ $1 == "-gender" ]
then
type=2
elif [ $1 == "-smile" ]
then
type=3
elif [ $1 == "-age" ]
then
type=4
else
echo "input aruments: extrac_att.sh -type att"
exit
fi
type_name=$1
echo "type is: $type"
echo "type_name is: $type_name"
type_num=$2
if [ $type_num == 0 ]
then
suffix="yellow_race"
elif [ $type_num == 1 ]
then
suffix="white_race"
elif [ $type_num == 2 ]
then
suffix="black_race"
elif [ $type_num == 3 ]
then
suffix="India_Arabia_race"
else
suffix="other_race"
fi
echo "type_num is $type_num"
#IFS(Internal Field Separator)是一个内部的环境变量,也是默认的文本分隔符,包括空格符(space character)、制表符(Tab)和换行符(\newline)
FINAL_IFS=$IFS #backup the original IFS
OLD_IFS=$IFS
IFS=$'\n' #set the new IFS
type_name=${type_name#*-}
echo $type_name.$type_num.$suffix
if [ -f "$type_name.$type_num.$suffix" ]
then
`rm $type_name.$type_num.$suffix`
fi
path_desti="$type_name.$type_num.$suffix"".folder"
if [ -d "$path_desti" ]
then
`rm -r $path_desti`
fi
`mkdir $path_desti`
output_num=0
for line in `cat gt-race-gender-smile-age`#read one line per time
do
IFS=$' ' #set the new IFS for sperate the line
arr=($line)
# echo ${#arr[@]}
# echo ${arr[$type]}
# echo $type_num
if [ "${arr[$type]}" == "$type_num" ] && [ "${arr[1]}" != "NULL" ] && [ "${arr[2]}" != "NULL" ] && [ "${arr[3]}" != "NULL" ]
then
echo $line
# echo $type_name
# echo $type_num
# type_name=${type_name#*-}
# echo "type_name is :$type_name"
echo ${arr[0]}
path="../${arr[0]}"
# path_desti="$type_name.$type_num.$suffix"".folder"
# if [ -d "$path_desti" ]
# then
# `rm -r $path_desti`
# fi
#
# `mkdir $path_desti`
#
`cp $path $path_desti`
echo $path
# exit
echo $line >> "$type_name.$type_num.$suffix"
output_num=$(expr $output_num + 1)
# exit
fi
IFS=$'\n'
done
echo "$type_name.$suffix is: $output_num"
echo "$type_name.$suffix is: $output_num" >> "static_num"
IFS=$FINAL_IFS