grep output placed into a while loop

自古美人都是妖i 提交于 2020-03-28 06:15:14

问题


I currently have my grep output configured to place everything in a file, i'm trying to set something up where a file will not need to be created.

    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

Above is my current setup, is there anyway i can set something up where i will not need to send this information to the test.txt file prior to running it in the while;do function. The python script will just output the status on screen. The test.txt file contains a list of numbers seperated by line for example

0
15
32
78
95

回答1:


Pipe your output directly into the 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


来源:https://stackoverflow.com/questions/14260416/grep-output-placed-into-a-while-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!