How can I show lines in common (reverse diff)?
On *nix, you can use comm. The answer to the question is:
comm -1 -2 file1.sorted file2.sorted
# where file1 and file2 are sorted and piped into *.sorted
Here's the full usage of comm
:
comm [-1] [-2] [-3 ] file1 file2
-1 Suppress the output column of lines unique to file1.
-2 Suppress the output column of lines unique to file2.
-3 Suppress the output column of lines duplicated in file1 and file2.
Also note that it is important to sort the files before using comm, as mentioned in the man pages.
Laravel collection opposite of diff
You can use duplicates method after mergging into single collection
$collection1 = collect([1,2,3,4]);
$collection2 = collect([1,5,6,4]);
$duplicates = $collection1
->merge($collection2)
->duplicates()
->values();
Will give you
Illuminate\Support\Collection {#1151
all: [
1,
4,
],
}
How to get opposite direction of `git diff origin/master`
Right: git diff commit-specifier
compares the given commit's tree to the work-tree, with the commit's tree on the "left side" as a/
and the work-tree on the "right side" as b/
. As you noted, it's tough to reverse these as the work-tree is implied by the lack of a second tree or commit specifier.
Fortunately, git diff
has a -R
option to reverse the two sides, so git diff -R commit-specifier
does the trick.
opposite of df.diff() in pandas
You can use rolling
with a window size of 2 and sum
:
df['f'] = df['d'].rolling(2).sum().shift(-1)
c d f
0 dd 1 3.0
1 ee 2 5.0
2 ff 3 7.0
3 gg 4 9.0
4 hh 5 NaN
cumsum the opposite of diff in r
The functions are quite different: diff(x)
returns a vector of length (length(x)-1)
which contains the difference between one element and the next in a vector x
, while cumsum(x)
returns a vector of length equal to the length of x
containing the sum of the elements in x
Example:
x <- c(1:10)
#[1] 1 2 3 4 5 6 7 8 9 10
> diff(x)
#[1] 1 1 1 1 1 1 1 1 1
v <- cumsum(x)
> v
#[1] 1 3 6 10 15 21 28 36 45 55
The function cumsum()
is the cumulative sum and therefore the entries of the vector v[i]
that it returns are a result of all elements in x
between x[1]
and x[i]
. In contrast, diff(x)
only takes the difference between one element x[i]
and the next, x[i+1]
.
The combination of cumsum
and diff
leads to different results, depending on the order in which the functions are executed:
> cumsum(diff(x))
# 1 2 3 4 5 6 7 8 9
Here the result is the cumulative sum of a sequence of nine "1". Note that if this result is compared with the original vector x
, the last entry 10
is missing.
On the other hand, by calculating
> diff(cumsum(x))
# 2 3 4 5 6 7 8 9 10
one obtains a vector that is again similar to the original vector x
, but now the first entry 1
is missing.
In none of the cases the original vector is restored, therefore it cannot be stated that cumsum()
is the opposite or inverse function of diff()
reverse diff functionality
Chances are, if you have diff
available, you will have grep
available too. So pipe the diff
output through grep
to check which result you get, and act accordingly. diff -qs
will output "Files a.txt and b.txt are identical" or "Files a.txt and b.txt differ". So you can check for the presence of "identical" in the output to find your case.
if diff -qs a.txt b.txt | grep -q identical; then
echo "Files are identical. Reporting"
else
# Do nothing
fi
Or as a oneliner:
(diff -qs a.txt b.txt | grep -q identical) && echo "Files are identical."
Related Topics
How I Should Run My Golang Process in Background
Difference Between Checkout and Export in Svn
Best Practices for Git Repositories on Open Source Projects
I Want to Contribute to the Linux Kernel
How the Util of iOStat Is Computed
How to Check Syslog in Bash on Linux
Getting Stacktrace from Core Dump
In Screen, How to Send a Command to All Virtual Terminal Windows Within a Single Screen Session
Internals of a Linux System Call
How to Perform a 'Git Pull' Without Re-Entering My Ssh Password
JSON Command Line Formatter Tool for Linux
Are Tar.Gz and Tgz the Same Thing
How to Create a Script to Save and Restore Permissions
What Is Active Memory and Inactive Memory
How to Understand "Cmpl $0X0, -0X30(%Rbp)"/"Je ..."
Ps Utility in Linux (Procps), How to Check Which CPU Is Used