Trying to write a bash script need some suggesstions.
Gurus,
I want to write a bash script to read a line by line from a file and execute in a command and redirect the output to a file.I am able to think through the below syntax but not sure how to redirect the output of the command to another file.Need suggestions. #/bin/bash for i in "cat /tmp/file" do command | grep "$i" done. Thanks in Advance. |
Just try:
Code:
#/bin/bash |
Given that each cmd is tun separately, you probably want '>>' i.e. append, instead of > (output), which will overwrite the file.
|
Code:
REPORT=/home/c9admin/amn_ami_delete3.rpt |
A slight alternative to shivaa's example and allowing the incorporation of chrism01's suggestion:
Code:
while read -r line |
If the "command" prints the same output every time, and you just want to capture all the matching lines from the file, then this would probably do you better:
Code:
command | grep -f /tmp/file > /path/to/output.txt |
All times are GMT -5. The time now is 12:17 PM. |