Re: diff

2021-12-14 Thread Yedidyah Bar David
On Tue, Dec 14, 2021 at 5:45 PM Mark E. Fuller  wrote:
>
>
> It's such a small thing, but I really enjoyed being privy to this
> question and discussion today.
>
> On 14/12/2021 17:21, Daniel Shahaf wrote:
> > אורי wrote on Tue, 14 Dec 2021 07:44 +00:00:
> >> Actually I prefer the "<(..)" method, because sometimes I want to compare 2
> >> commands:
> >>
> >> diff <(pip freeze | sort) <(cat requirements.txt | sort)
> >>
> >
> > Consider s/diff/comm -12/.
> >
> >> Or even use cat and echo to add a specific line to one of the outputs. If I
> >> want the result to be completely null. For example to run in crontab and
> >> send me mail whether it's not null.
> >
> > Careful here.  By default, cron jobs run not under your login shell but
> > under /bin/sh, and it's possible the latter doesn't support «<(…)» even
> > if the former does.
>
> Out of curiosity I asked the internet:
> https://unix.stackexchange.com/questions/159513/what-are-the-shells-control-and-redirection-operators
>
> Looks like < as a redirect is POSIX-compliant, but as soon as it's
> <(...) it's not a redirect anymore but instead a process substitution
> which is implemented in BASH, ZSH, etc.:
> https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution
> https://zsh.sourceforge.io/Intro/intro_7.html
>
> Nice to learn a new trick - I probably would have just redirected to a
> temp file instead of the compact solution discussed today.

If we are heading in this direction, may I remind of another, likely
POSIX-compliant
(didn't check), more "traditional" way, that still does not require
(much) I/O, at least on
any reasonably-modern *nix (perhaps e.g. not including cygwin etc. -
again, didn't check):

$ mkfifo pipe1
$ mkfifo pipe2
$ command1 > pipe1 &
$ command2 > pipe2 &
- These are now blocked, waiting in the background until someone reads
from the pipes
$ diff pipe1 pipe2
- After 'diff' finishes reading, command1 and command2 will finish too.
- On a job-controlling shell, you'll get some messages about this.
$ rm pipe1 pipe2

Best regards,
-- 
Didi

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: diff

2021-12-14 Thread אורי
comm -3 works here.
אורי
u...@speedy.net


On Tue, Dec 14, 2021 at 6:45 PM Daniel Shahaf 
wrote:

> אורי wrote on Tue, 14 Dec 2021 15:32 +00:00:
> > אורי
> > u...@speedy.net
> >
> >
> > On Tue, Dec 14, 2021 at 5:22 PM Daniel Shahaf 
> > wrote:
> >
> >> אורי wrote on Tue, 14 Dec 2021 07:44 +00:00:
> >> > Actually I prefer the "<(..)" method, because sometimes I want to
> >> compare 2
> >> > commands:
> >> >
> >> > diff <(pip freeze | sort) <(cat requirements.txt | sort)
> >> >
> >>
> >> Consider s/diff/comm -12/.
> >>
> >
> > ???
>
> s/foo/bar/ means "change foo to bar".  In this case, I was referring you
> to comm(1).  Your use-case there is right up comm(1)'s alley.
>
> «-12» is an argument to to comm(1).
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: diff

2021-12-14 Thread Daniel Shahaf
אורי wrote on Tue, 14 Dec 2021 15:32 +00:00:
> אורי
> u...@speedy.net
>
>
> On Tue, Dec 14, 2021 at 5:22 PM Daniel Shahaf 
> wrote:
>
>> אורי wrote on Tue, 14 Dec 2021 07:44 +00:00:
>> > Actually I prefer the "<(..)" method, because sometimes I want to
>> compare 2
>> > commands:
>> >
>> > diff <(pip freeze | sort) <(cat requirements.txt | sort)
>> >
>>
>> Consider s/diff/comm -12/.
>>
>
> ???

s/foo/bar/ means "change foo to bar".  In this case, I was referring you
to comm(1).  Your use-case there is right up comm(1)'s alley.

«-12» is an argument to to comm(1).

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: diff

2021-12-14 Thread Mark E. Fuller


It's such a small thing, but I really enjoyed being privy to this 
question and discussion today.


On 14/12/2021 17:21, Daniel Shahaf wrote:

אורי wrote on Tue, 14 Dec 2021 07:44 +00:00:

Actually I prefer the "<(..)" method, because sometimes I want to compare 2
commands:

diff <(pip freeze | sort) <(cat requirements.txt | sort)



Consider s/diff/comm -12/.


Or even use cat and echo to add a specific line to one of the outputs. If I
want the result to be completely null. For example to run in crontab and
send me mail whether it's not null.


Careful here.  By default, cron jobs run not under your login shell but
under /bin/sh, and it's possible the latter doesn't support «<(…)» even
if the former does.


Out of curiosity I asked the internet: 
https://unix.stackexchange.com/questions/159513/what-are-the-shells-control-and-redirection-operators


Looks like < as a redirect is POSIX-compliant, but as soon as it's 
<(...) it's not a redirect anymore but instead a process substitution 
which is implemented in BASH, ZSH, etc.:

https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution
https://zsh.sourceforge.io/Intro/intro_7.html

Nice to learn a new trick - I probably would have just redirected to a 
temp file instead of the compact solution discussed today.


Cheers,

Daniel



אורי
u...@speedy.net


On Tue, Dec 14, 2021 at 9:31 AM Eli Marmor  wrote:


Use "-" instead the file name of one of both of the files, and pipe your
output to the diff command.

‪On Tue, 14 Dec 2021 at 09:12, ‫אורי‬‎  wrote:‬


Thank you.

אורי
u...@speedy.net
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il





___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il



Mark E. Fuller, Ph.D.
HaShikma 19, Apt. 24
Nesher 3681219, Israel
+972 (0)53-872-6579
+49 (0)1577 1848188
+1 401-214-4266
mark.e.ful...@gmail.com
mark.e.ful...@gmx.de
ful...@stossrohr.net
@fuller:one.ems.host
https://www.stossrohr.net
PGP Fingerprint: 73F1 A30C BDF4 DB4B C75F FD0F D599 E76C FFCA BF60

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: diff

2021-12-14 Thread אורי
אורי
u...@speedy.net


On Tue, Dec 14, 2021 at 5:22 PM Daniel Shahaf 
wrote:

> אורי wrote on Tue, 14 Dec 2021 07:44 +00:00:
> > Actually I prefer the "<(..)" method, because sometimes I want to
> compare 2
> > commands:
> >
> > diff <(pip freeze | sort) <(cat requirements.txt | sort)
> >
>
> Consider s/diff/comm -12/.
>

???


>
> > Or even use cat and echo to add a specific line to one of the outputs.
> If I
> > want the result to be completely null. For example to run in crontab and
> > send me mail whether it's not null.
>
> Careful here.  By default, cron jobs run not under your login shell but
> under /bin/sh, and it's possible the latter doesn't support «<(…)» even
> if the former does.
>

Yes, I changed crontabs to bash today.

אורי
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: diff

2021-12-14 Thread Daniel Shahaf
אורי wrote on Tue, 14 Dec 2021 07:44 +00:00:
> Actually I prefer the "<(..)" method, because sometimes I want to compare 2
> commands:
>
> diff <(pip freeze | sort) <(cat requirements.txt | sort)
>

Consider s/diff/comm -12/.

> Or even use cat and echo to add a specific line to one of the outputs. If I
> want the result to be completely null. For example to run in crontab and
> send me mail whether it's not null.

Careful here.  By default, cron jobs run not under your login shell but
under /bin/sh, and it's possible the latter doesn't support «<(…)» even
if the former does.

Cheers,

Daniel


> אורי
> u...@speedy.net
>
>
> On Tue, Dec 14, 2021 at 9:31 AM Eli Marmor  wrote:
>
>> Use "-" instead the file name of one of both of the files, and pipe your
>> output to the diff command.
>>
>> ‪On Tue, 14 Dec 2021 at 09:12, ‫אורי‬‎  wrote:‬
>>
>>> Thank you.
>>>
>>> אורי
>>> u...@speedy.net
>>> ___
>>> Linux-il mailing list
>>> Linux-il@cs.huji.ac.il
>>> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>>>
>>
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il