shell 读取并处理文本信息

#!/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值