Wednesday, April 13, 2022

[SOLVED] GNU shell doing multiple things in a nested diff all at once

Issue

I am trying to do a few things in a single line and this is my attempt:

coolc -P p good.cool | xargs -I {} sh -c "diff <(sed 's/@[0-9]+/@/g' {}) <(sed 's/@[0-9]+/@/g' good.out)"
  1. I have a file called good.out and I want to run sed on it: sed 's/@[0-9]+/@/g' good.out
  2. I want to run coolc -P p good.cool which prints result to stdout
  3. I want to use the output from (2) in sed 's/@[0-9]+/@/g' {}
  4. I want to diff (1) and (3)

Is it possible doing all of these without creating a new files and all in a single line?


Solution

Assuming that the original code was wrong to use xargs, and you really want to run diff only once:

diff <(coolc -P p good.cool | sed 's/@[0-9]+/@/g') \
     <(sed 's/@[0-9]+/@/g' good.out)


Answered By - Charles Duffy
Answer Checked By - David Goodson (WPSolving Volunteer)