0

I have an alias which I use to strip out comments that are piped to it:

alias decomment='egrep -v "(^#.*|^$)"'

I'm currently having some difficulty with a squid proxy setup, so I want to compare come config changes. I want to use my decomment alias, as the squid.config file has a large number of commented-out lines.

How would I compare (using diff) the output of these two commands, in one line?

$ cat squid.conf.old | decomment 

$ cat squid.conf.new | decomment

..in the way I can this way:

$ cat squid.conf.old | decomment > output1

$ cat squid.conf.new | decomment > output2

$ diff output1 output2
don_crissti
  • 79,330
  • 30
  • 216
  • 245
paradroid
  • 1,159
  • 1
  • 13
  • 28

2 Answers2

2

You can use process substitution for this:

diff <(decomment < squid.conf.old) <(decomment < squid.conf.new)
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • The output is exactly the same as the other answer. The other way is more like what I am used to and understand more, but is this answer more 'correct', as in better practice? – paradroid Nov 23 '18 at 22:51
  • The other answer makes UUOC which is generally deprecated. This one IS better practice and you should get used to it. – RudiC Nov 23 '18 at 23:03
1

You can use process substitution:

diff <(cat squid.conf.old | decomment) <(cat squid.conf.new | decomment)
ralz
  • 1,956
  • 12
  • 17