将grep输出放入while循环中

时间:2013-01-10 14:41:44

标签: ksh do-while grep

我目前将我的grep输出配置为将所有内容放在一个文件中,我正在尝试设置一些不需要创建文件的内容。

    func_database () {
egrep "^[0-9]" file.txt | egrep "/ON /" | sed s/-[^@]*$// > /users/home/myhome/log/test.txt
}

                                    func_database
            while read -r line ; do
                                    echo "Database $line Area a:" 
            python amgr.py status $line a
            echo ""
                        echo "Database $line Area b:" 
            python amgr.py status $line b
            echo ""
                        echo "Database $line Area c:" 
            python amgr.py status $line c
            echo ""
            done </users/home/myhome/log/test.txt

以上是我目前的设置,无论如何我可以设置一些东西,我不需要在while.do函数运行之前将此信息发送到test.txt文件。 python脚本只会在屏幕上输出状态。 test.txt文件包含按行分隔的数字列表,例如

0
15
32
78
95

1 个答案:

答案 0 :(得分:0)

将输出直接输入while

func_database () {
    egrep "^[0-9]" file.txt | egrep "/ON /" | sed s/-[^@]*$//
}
func_database |
while read -r line
do
    echo "Database $line Area a:" 
    python amgr.py status $line a
    echo ""
    echo "Database $line Area b:" 
    python amgr.py status $line b
    echo ""
    echo "Database $line Area c:" 
    python amgr.py status $line c
    echo ""
done
相关问题