Q: Bash - need to write data to a file based on output of a command in bash I have a bash script which checks IP Addresses in a file line by line and executes a command with that IP saved in a variable .
I wanted to add a few lines of bash which would write that IP to a new file when the output of the command is something specific. 
I would be grateful if anyone shed some light on this matter.

A: Assuming you stored the output of the command to a variable named output, you can do something like:
# $output is the output you got
# $expected is the expected value
# $IP is IP you just checked

if [ "$output" == "$expected" ]; then
    echo $IP >> file.txt
fi

replace file.txt with the name of the file name you prefer.
