问题
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