Home > Mobile >  Bash Comparing two types of outputs with long strings
Bash Comparing two types of outputs with long strings

Time:07-20

I have a known good configuration of x.yml. That configuration consists of 30 lines of code with only 8 lines NOT commented out, two of those lines NOT commented out are completely blank.
So my results look like

This is an output from grep -v '#' /mnt/data/x.yml

node.name: 123
path.data: "/mnt/data/data"
pipeline.workers: 4
pipeline.batch.size: 250


http.port: 9600-9700
path.logs: "/mnt/data/logs"

Or very similar to that at least.

How would I take that string and compare it to the output from another x.yml if I was using it for troubleshooting?

Would I just compare two strings like:

if [ "$goodYML" = "$outputYML" ]; then
  echo "equal"
else
  echo "not equal"
fi

and declare that whole string above as a variable and then how would I set the output of my grep to a string?

CodePudding user response:

You could use process substitution

diff <(grep -v '^#' /mnt/data/x.yml) <(grep -v '^#' /mnt/data/y.yml)

Any commands can be put between the <( YOUR COMMAND HERE )


EDIT

Since your file is not local, you could do:

diff <(grep -v '^#' /mnt/data/x.yml) <(ssh user@host grep -v '^#' /mnt/data/y.yml)

All pertinent details should be in the question.

  • Related