忽略shell脚本中的输入

时间:2015-04-20 14:31:18

标签: shell

我在shell脚本中导出一个.txt文件,该文件有一些内容。这个shell脚本是由python代码调用的。当我运行python代码时,它将输入请求为:

Enter the list : aaf|hgj|hju
在给出输入(aaf | hgj | hju)并按下输入后,显示输出为:

aaf belongs to : city name
hgj belongs to : city name
hju belongs to : city name

(aaf|hgj|hju) are these entries are present in .txt file.

我的要求是,如果我提供输入为(aaf | hgj | hju | ggg),其中ggg不存在于.txt文件中,它应该显示:

ggg is wrong input
aaf belongs to : city name
hgj belongs to : city name
hju belongs to : city name

对于其他三个来说意味着它应该是我原样。

下面的

是shell脚本的示例代码:

#!/bin/ksh

export fName="/fsnadmin/SAAS_SUPPORT/pod_data_from_FM.txt"

pdcats=""
        pdcas=""
        export fstrs=$1
        #dcs="US1 - ADC"
        pList=`awk '{ print $1 }' RS="|" <<< $fstrs`
        for item in ${pList[*]}
        do
                item=`echo $item|sed 's/\^//'|sed 's/\\$//'`
                len=${#item}

                if [ $len -gt 3 ]; then
                        item=`echo $item|sed 's/-MC//'|sed 's/\^//'|sed 's/\\$//'`
                fi
                item=`echo $item`

                pdcats=`cat $fName| egrep -e "$dcs" |awk -F':' '{print $1}'|grep -i ^$item\$`

                if [ "$pdcats" != "" ]; then
                        len=${#pdcats}
                        if [ $len -gt 3 ]; then
                                pdcas=`echo $pdcas"^"$pdcats"-MC$|"`
                        else
                                pdcas=`echo $pdcas"^"$pdcats"$|"`
                        fi
                fi
        done

0 个答案:

没有答案
相关问题