如何在不使用Bash中的临时文件的情况下区分两个管道?假设您有两个命令管道:
foo | bar
baz | quux
Run Code Online (Sandbox Code Playgroud)
而且你想diff在他们的输出中找到它们.一个解决方案显然是:
foo | bar > /tmp/a
baz | quux > /tmp/b
diff /tmp/a /tmp/b
Run Code Online (Sandbox Code Playgroud)
是否可以在Bash中不使用临时文件的情况下这样做?您可以通过在其中一个管道中管道来消除一个临时文件:
foo | bar > /tmp/a
baz | quux | diff /tmp/a -
Run Code Online (Sandbox Code Playgroud)
但是你不能同时将两个管道同时传输到diff中(至少不是以任何明显的方式).是否有一些聪明的技巧涉及/dev/fd不使用临时文件这样做?
我有两个包含信息行的字符串.我想获得两个字符串中不同的行.示例:String1:
"This is line1
This is line2
This is line3"
Run Code Online (Sandbox Code Playgroud)
String2的:
"This is line1
This is linex
This is line2"
Run Code Online (Sandbox Code Playgroud)
结果预期:
diff string1 string2 is:
"This is line3"
diff string2 string1 is:
"This is linex"
Run Code Online (Sandbox Code Playgroud) 鉴于这两个字符串:
"12345"
"1245"
Run Code Online (Sandbox Code Playgroud)
第一个是完整的字符串,第二个是第一个缺少的东西,我希望它返回“3”。
所以再次:
"The ball is red"
"The is red"
Run Code Online (Sandbox Code Playgroud)
我要回“球”
我试过 diff 与:
diff <(echo "12345") <(echo "1245")
Run Code Online (Sandbox Code Playgroud)
但是 diff 没有给出所需的输出。comm 也不做我想要的。
我有2个字符串,我想要它们之间的git diff。我可以创建file1并添加string1作为其内容。
然后,我可以创建file2并添加string2作为其内容。然后我可以git diff file1和file2。
但是,鉴于我将字符串作为字符串(而不是文件内容),可以避免这些繁琐的步骤吗?有没有更简单的方法?
就像是:
git diff "my first string" "my second string" # obviously does not work
Run Code Online (Sandbox Code Playgroud)