date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,384,262,383,000 |
This is a follow up question from Sort large CSV files (90GB), Disk quota exceeded.
So now I have two CSV files sorted, as file1.csv and file2.csv
each CSV file has 4 columns, e.g.
file 1:
ID Date Feature Value
01 0501 PRCP 150
01 0502 PRCP 120
02 0501 ARMS 5.6
02 0502 ARMS 5.6
file 2:
ID Date Feature Val... |
Let's review tools that combine two files together line by line in some way:
paste combines two files line by line, without paying attention to the contents.
comm combines sorted files, paying attention to identical lines. This can weed out identical lines, but subsequently combining the differing line would require ... | diff two large CSV files (each 90GB) and output to another csv |
1,384,262,383,000 |
I'm trying to create and apply a simple patch to fix a bug with gradle.
I copy the file (/usr/bin/gradle) to my working directory, then make the change. I then create the patch:
diff -u /usr/bin/gradle gradle > gradle.patch
Then I attempt to apply it:
sudo patch < gradle.patch
Reversed (or previously applied) patch ... |
You need to patch the right file.
The way you call it, it will try to patch the new file and thus correctly assumes a reversed patch.
Try to copy an old version of the file to your current directory and the patch will apply.
Regarding your -p0 test: do you have permission to modify /usr/bin/gradle?
Do you have permiss... | How to apply simple patch (reverse detected) |
1,384,262,383,000 |
I would like to know if i can use the diff tool to take the difference between two folders which contain sources as well as libraries and executable.
Right now i gave
diff -Naur dir1/ dir2/
It is comparing the executables within the directories and is dumping junk values.
Is there any way to remove the libraries ... |
Don't use the -a switch.
diff -Nur dir1/ dir2/
This will only output 'Files dir1/afile and dir2/afile differ' on binary files.
| How to use diff tool to take a diff between directories with libraries and source? |
1,384,262,383,000 |
I would like to merge two non-git-based text files using semantics that are similar to to how git depicts "merge conflicts".
For example, suppose I have two text files with similar but not identical content, called file.1 and file.2. I would like to perform a merge of these two files into a third file, as follows:
hyp... |
Due to the limitations of the solutions I originally posted in my first "Answer" here which involve diff -D ... and diff -U ..., I decided to write a solution in python, using python's difflib module.
I wrote it to produce output which looks relatively similar to the "merge conflict" output from git. It utilizes delim... | Merging two non-git-based text files with similar semantics to the depiction of git merge conflicts |
1,384,262,383,000 |
Is there are way to use utility like diff to find the difference in metadata of two identical file hierarchies? If I have two identical file structures like
root_folder/
file1
file2
folder1/
file3
The diff utility will usually exit as though they are identical but adding them to tarballs will prod... |
I highly recommend diffoscope in this sort of situation.
You can run it before creating the tarballs, as
diffoscope dir1 dir2
to find the differences between the two directories (including metadata), or after creating them, as
diffoscope tarball1.tar tarball2.tar
to find the differences between the two tarballs.
| Diffing for metadata differences |
1,384,262,383,000 |
I am trying to compare 2 directories ( A / B ) in Linux and DELETE any files from B which DO NOT exist in A.
For example, if file '1.jpg' exists in Directory B but does not exist in Directory A then it needs to be deleted from B.
I have tried using diff but all the files are essentially different so it doesn't seem to... |
rsync can do what you want quickly and easily:
rsync --dry-run --verbose --recursive --existing --ignore-existing --delete-after A/ B/
From the help:
--existing skip creating new files on receiver
--ignore-existing skip updating files that already exist on receiver
--delete delete... | Find missing file names between 2 directories in Linux |
1,384,262,383,000 |
I have a small project folder with text files, which I'd like to post somewhere in order to ask a question on a forum. Let's take, in the simplest case, that I have something like this:
mkdir aaa
cd aaa
echo AAA > aaa.txt
mkdir bbb
echo BBB > bbb/bbb.txt
Obviously, I'd like the subfolder structure:
aaa/
├── aaa.txt
└... |
Using only diff, you need a reference (empty) directory to compare things against:
mkdir /tmp/scratch
diff -urN /tmp/scratch /tmp/aaa
Using git, git diff should give you the output you're looking for.
To handle binaries, use git diff --binary; this will produce an encoded patch which git apply will know how to handle... | Packaging a directory and its contents as a diff patch? |
1,384,262,383,000 |
I have two large tab-delimited files (>10GB) and I know that when they're sorted, they're identical in content.
However, I'm interested in the order of rows and the index of the swapped ones when they share the same "key" (key here being defined as rows grouped based on Source and Location columns).
In other words, ro... |
This is one of those rare occasions when I'd probably use getline due to the size of your input files so we only save a handful of lines in memory at a time instead of >10G:
$ cat tst.awk
BEGIN {
OFS = "\t"
print "Group_Source:Location", "df1.index", "df2.index"
}
NR != FNR { exit }
{ srcLoc = $3 ":" $4 }
srcL... | Extract the indexes of rows that are swapped in order between two files |
1,384,262,383,000 |
File# 1:
test1,1
test2,2
test3
File# 2:
test2
test1
test4
Desired Output:
test4
|
You can use grep for this:
$ grep -vwf <(cut -d, -f1 file1) file2
test4
Explanation
grep options:
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-w, --word-regexp
Select only those lines containing matches that form
whole words.
-f FILE, --file=FILE
Ob... | Compare 2 files based on the first column and print the not matched |
1,384,262,383,000 |
I have two files, (no blank lines/Spaces/Tabs)
/tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
/tmp/required
SearchText.json
and the end output I want is : (all uncommon lines from /tmp/all)
aa
bb
cc
hello
xyz.txt
I have tried below commands :-
# comm -23 /tmp/required /tmp/all
SearchTex... |
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line ... | bash remove common lines from two files |
1,384,262,383,000 |
Consider a directory with the following files:
file1
file1.suffix
file2
file3
file3.suffix
I need to list all files such that there doesn't exist another file having the same name and a known suffix. In the example above that would match only file2.
This is what i came up with:
diff --new-line-format= --unchanged-lin... |
With zsh:
setopt extendedglob # for the first "^" below
ls -ld -- ^*.suffix(^e:'[[ -e $REPLY.suffix ]]':)
(or use ^*.* instead of ^*.suffix if you only want to consider the extension-less files, or, following the update to your question *.(org|net|com) or ^*.*.* or ^*.(signed|jnl|jbk)...)
That is list the non-.suffix... | List files not having another file with suffix |
1,384,262,383,000 |
So I have two language files, english and french. They are in this format:
key=translation
An example in English would be:
ui.title=My Title
And in French:
ui.title=Mon Titre
So I need a script that reads the language files and finds the differences. So say that the English file had keys:
ui.title=Title
ui.close=Cl... |
You could use:
grep -v -f <(sed -r 's/([^=]*).*$/\1/' fr.i18n.txt) en.i18n.txt
Which filters all keys from fr.i18n.txt from en.i18n.txt.
Example:
$ cat > en.i18n.txt
ui.title=Title
ui.close=Close
ui.edit=Edit
ui.accept=Accept
^D
$ cat > fr.i18n.txt
ui.title=Titre
ui.edit=Modifier
^D
$ grep -v -f <(sed -r 's/([^=]*).*$... | Find differences in file and sorting file by key |
1,384,262,383,000 |
When using git diff, how can I ignore changes which start with # ?
For normal diff command, I would use something like:
diff <(grep -v '^#' file1) <(grep -v '^#' file2)
But none of the suggested solutions below work!
Is there really no way to see git diff with comments omitted?
UPDATE:
I tries this in my .gitconfig:
... |
It’s possible to do this by filtering all files before diffing them.
First, write a small helper, and call it stripcomments (executable, somewhere on your PATH):
#!/bin/sh -
exec grep -ve '^#' -- "$@"
Then configure a git diff mode using this helper:
git config diff.nocomments.textconv stripcomments
(this will confi... | git diff: ignore comments |
1,384,262,383,000 |
Basically I want to check the difference of the same file before and after a sed
Tried to run:
diff /opt/postTrades.sh <<< $(sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh)
and
diff <<< $(sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh) < /opt/postTrades.sh
and
diff <<< (sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh) < /opt... |
diff needs two file operands. With a here-string, you pass input to diff on its standard input.
To make diff read from standard input, use - as the filename:
$ diff file - <<<"$( sed 'expression' file )"
or, more portably,
$ sed 'expression' file | diff file -
If you are using a shell that supports process substitu... | Diff between a string and a file |
1,384,262,383,000 |
Is there an option to have diff (-q) not look at file contents and instead just look at size and mtime? If not, is there a tool similar to this that has the option?
|
Use rsync, but tell it not to copy or remove any files.
rsync -a -nv --delete a/ b/
| Diff directories using modification time (mtime) and size instead of contents |
1,384,262,383,000 |
I am looking from something which gives me an output of comm -3 on two sorted outputs (line-by-line comparison, only additional/missing lines from either side) but which looks more like the output from diff -y, e.g. in that it uses the whole width.
file1:
bar/a
bar/feugiat
bar/libero
bar/mauris
bar/scelerisque
bar/urn... |
You could pipe to:
expand -t "$((${COLUMNS:-$(tput cols)} / 2))"
Or for the angle brackets:
awk -v cols="${COLUMNS:-$(tput cols)}" '
BEGIN {width = cols/2-1; space = sprintf("%*s", width, "")}
/^\t/ {print space ">", substr($0, 2); next}
{printf "%-*s<\n", width, $0}'
If your tput doesn't output the number of ... | Naive line-by-line comparison like "comm -3" but looking like "diff -y" |
1,428,576,601,000 |
For example:
file1.txt:
I need to buy apples.
I need to run the laundry.
I need to wash the dog.
I need to get the car detailed.
file2.txt
I need to buy apples.
I need to run the laundry.
I need to wash the car.
I need to get the car detailed.
file3.txt
I need to wash the car.
If I do diff file1.txt file2.txt,
the ... |
A workaround would be to strip of the corresponding lines and then diff it. That's to say, both file1 and file2 would look like:
I need to buy apples.
I need to run the laundry.
I need to get the car detailed.
You can do this using a combination of grep, perl and sed:
$ lines_to_ignore=$(grep -nFf file3 file2 | perl... | How to make diff command ignore certain lines of second file(bash)? |
1,428,576,601,000 |
I have two text files. File 2 has logs over 1,000,000. File 1 has IP addresses line by line. I want to read file 2 lines and search these lines in file 1, I mean:
file 1:
34.123.21.32
45.231.43.21
21.34.67.98
file 2 :
34.123.21.32 0.326 - [30/Oct/2013:06:00:06 +0200]
45.231.43.21 6.334 - [30/Oct/2013:06:00:06 +0200]
... |
Join + sort
If you're trying to find IP's that are present in both, you can use the join command but you'll need to use sort to pre-sort the files prior to joining them.
$ join -o 2.2 <(sort file1) <(sort file2)
Example
$ join -o 2.2 <(sort file1) <(sort file2)
1.765
0.326
4.754
3.673
6.334
Another example
file 1a:
... | compare files line by line and create new one bash programming |
1,428,576,601,000 |
I have set up diff-highlight as pager / highlighter for git.
[pager]
log = diff-highlight | less
show = diff-highlight | less
diff = diff-highlight | less
That works perfectly.
But how can I use diff-highlight for normal diff ?
|
You can define a function:
diff() { /usr/bin/diff "$@" | diff-highlight }
diff-highlight processes unified diffs (diff -u) but piping other formats appears to work — it passes them through unchanged.
To approximate the behaviour you get with git diff, you’d need colordiff too:
diff() { colordiff -u "$@" | diff-highli... | use 'diff-highlight' for diff |
1,428,576,601,000 |
I want a live view of diffs while I am editing a file. vimdiff is able to do something I want, like highlighting the differences between two files.
However there are two drawbacks of vimdiff that holds me back.
First, it cannot buffer the same file independently to allow a diff comparison. This problem can be easily... |
After looking into autocmd in vimdoc, I think I have found the solution that does exactly what I want:
autocmd CursorMoved,CursorMovedI * diffupdate
Many thanks to Ingo for his suggestion!
| Live diff-mode editing in vim |
1,428,576,601,000 |
diff3 on files finds no difference:
$ grep -P '\[\[.*?\]\]' -o intro.tex | sort > A.txt
$ grep -P '\[\[.*?\]\]' -o intro.tex | sort | uniq > B.txt
$ grep '\\pnum %% \[\[' intro.tex | sed 's/\\pnum %% //' | sort > C.txt
$ diff3 A.txt B.txt C.txt | wc -l
0
diff3 on process substitutions running the same commands finds ... |
If we run diff3 under strace -f:
$ strace -qqfe execve -e signal=none diff3 a b c
execve("/usr/bin/diff3", ["diff3", "a", "b", "c"], 0x7ffef2bb2d78 /* 53 vars */) = 0
[pid 13360] execve("/usr/bin/diff", ["diff", "--horizon-lines=100", "--", "b", "c"], 0x7ffc019c6d50 /* 53 vars */) = 0
[pid 13361] execve("/usr/bin/diff... | Why diff3 on inputs from process substitution finds a difference while diff3 on same data in files finds no difference? |
1,428,576,601,000 |
The case is following. I have two files: file1.c, file2.c
ls
file1.c file2.c patch.diff
patch < patch.diff
...
x out of x hunk FAILED -- saving rejects to file file1.c.rej
(the same with file2.c)
ls
file1.c file2.c file1.c.orig file2.c.orig file1.c.rej file2.c.rej patch.diff
patch -R < patch.diff # I thought it will... |
It is always a good idea to make backup copies from the original files.
This can be done automatically if you call patch with option -b.
Background: in case that there is no .rej file, you could call:
patch -R
to reverse the patch, but this does not work in case of a problem.
Note that in case that file2.c.orig alrea... | How to undo after patch is applied? .rej/.orig files |
1,428,576,601,000 |
I have a text file full of several hundred lines of sequences like this:
b 29.
b 52.
c 84.
c 83.
c 94.
c 93.
c 61.
b 38.
c 81.
c 92.
c 28.
c 37.
c 27.
lara@batcuter:~/.asd/a-new-way-of-studying-go$ wc -l game7
271 game7
and the following script, which sep... |
Tell the person who suggested || that he's an idiot. Using || makes the snippet read all the lines from fileA first, then all the lines from fileB, because as long as read lineA returns true, read lineB is not executed. Instead, call read both times, saving the return status, then test the return statuses.
while
I... | Reading two files into an IFS while loop -- Is there a way to get a zero diff result in this case? |
1,428,576,601,000 |
I'm searching a GUI [or CLI] tool that can produce output like the Total Commander compare content function does! For example:
Are there any that do that? It's a very handy tool and I miss it
|
xxdiff
gtkdiff
tkdiff
come to my mind.
| Total Commander "compare content" like alternative? |
1,428,576,601,000 |
I may be missing some information here, but I was surprised today when I tried to run diff on two .html files that should have a subtle difference and got this message:
$ diff index.html index3.html
Binary files index.html and index3.html differ
Why are .html files being considered binaries? Is there any way to avoid... |
GNU diff treats files as binary if there is a null byte within the first few kilobytes. Text files don't contain null bytes, and binary files are very likely to contain null bytes within the first few hundred bytes, so this is a good heuristic. The file name doesn't matter.
The reason diff doesn't display differences ... | Diff identifying html files as binary |
1,428,576,601,000 |
I have two dirs dir1 and dir2 that have hundreds of subdirectories at depth 1. I only need information of the subdirectory names that are common between dir1 and dir2 and systematically delete them from dir2. I don't need to compare files or content of files. Performing
diff -qr dir_one dir_two | sort
produces the fi... |
For your use case you can avoid to identify the common directories because rm -rf just ignores non-existing ones.
So it's enough to find all directories in dir1 and delete them from dir2:
find dir1 -mindepth 1 -maxdepth 1 -type d -printf "dir2/%f\0" |xargs -0 rm -rf --
Some explanations. By default find would print... | Identify common subdirectory names between two different directories and delete them |
1,428,576,601,000 |
I currently try to monitor two directories and subdirectories for changes in files. The directories contain the same set of files, some of them are changed. So I thought I might use the diff command to create a list of changed files with the line numbers and changes. I need this list to further process it by another s... |
I think this ought to do what you need:
diff -r -U0 a/ b/ | awk '/^+++ / {filename=$2; next} /^@@ / {split($3,a,","); line=substr(a[1],2)} /^+/ {text=substr($0,2); print filename ":" line ":" text; line++}'
Basically, it does an ordinary recursive diff, and then discards the bit you don't want. awk is cool for stuff ... | diff two directories for changes and format output to use for script |
1,428,576,601,000 |
I want to quickly compare files in two different directories to see if the files are the same (same content). I want to see the results in Kompare (I'm on KDE - Kubuntu 12.04).
Here's my diff command:
diff -EwbBsy /directory/one /directory/two
(That command would suit me even better if it ignored any files in /direct... |
It doesn't seem to be able to handle the -y switch which does the side-by-side style of diff, but you can use the unified diff (-u). You can't mix these 2 styles so it's either -y or -u. So doing this worked for me:
$ diff -EwbBsu /directory/one /directory/two | kompare -o -
This will not show the entire file with th... | How to pipe diff into Kompare? |
1,428,576,601,000 |
The goal is to change some parameters on a lot of devices on connections that are kind of unreliable (wireless)--according to csv that has the format: IP,Parameter,Parameter
I would like to make a bash script that uploads a file, then checks the contents of it against the local copy, then run other commands using only... |
In this case, if I remember correctly, the answer was in the above comment about using ControlMaster. Thanks @Jakuje!
| How to upload a file and then check it and run some other commands using only ssh, cat, and diff in a single SSH session? |
1,428,576,601,000 |
I have two files, expected.out and actual.out with:
PID(12345)
PID(01234)
respectively.
I want diff to ignore the line if only the 5 numbers are different, so diff would return empty. The idea is to for diff to ignore logs that have different PIDs but are otherwise identical.
The following doesn't work:
diff -I '\([0-... |
Match the beginning ^ and end of the line $ and also match the string PID (you don't want FOO(12345) and BAR(12345) to be ignored):
diff -I '^PID([0-9]\{5\})$' expected.out actual.out
It's safer to match one or more digits than to assume that each PID has 5 digits:
diff -I '^PID([0-9]\+)$' expected.out actual.out
| How to get linux 'diff' to work with regex expression in bash |
1,428,576,601,000 |
I have two text files, and I want to compare their corresponding values according to their rows and columns. By comparing, I mean to check if the values are equal and echo if the values are the same or not. Here are the files:
file1.txt
Name Col1 Col2 Col3
-----------------------
row1 1 4 7
row2 ... |
There are many ways to do it, here's a solution with gawk 4.x:
$ awk '
FNR < 2 { next }
FNR == NR {
for (i = 2; i <= NF; i++) {
a[$1][i] = $i;
}
next;
}
($1 in a) {
for (i = 2; i <= NF; i++) {
if (a[$1][i] == $i) {
printf("%s->Col%d: Equ... | Comparing text files using Bash and AWK |
1,428,576,601,000 |
I'm trying to write a script that notifies me when a static web page has changed. To do it, I'm using wget to download the web page, and diff to check whether it has changed or not. I'm running an Ubuntu 20.04 LTS virtual machine. Here is the example:
$ wget --quiet https://twiki.di.uniroma1.it/twiki/view/Reti_Avanzat... |
You can solve this problem by using w3m with -dump option that ignores tags while rendering the page.
$ w3m -dump https://twiki.di.uniroma1.it/twiki/view/Reti_Avanzate/InternetOfThings2021 > file1
$ w3m -dump https://twiki.di.uniroma1.it/twiki/view/Reti_Avanzate/InternetOfThings2021 > file2
$ if cmp -s file1 file2; ... | Why downloading the same web page twice with wget results in two files which differ? |
1,428,576,601,000 |
Does the Linux implementation if diff -w discard \n?
I don't have access to a Linux machine to check that out.
|
The -w flag means:
-w --ignore-all-space
Ignore all white space.
Now, this isn't very clear becase "white space" actually includes \n usually. For example, the \s class in Perl Compatible Regular Expressions or the POSIX [[:space:]] both match a newline character:
$ printf '\n' | grep -zqP '\s' && echo yes
yes
$ ... | Linux diff command, is it discarding newlines? |
1,428,576,601,000 |
top1
1,facebook.com
2,google.com
3,youtube.com
4,yahoo.com
5,wikipedia.org
6,baidu.com
7,live.com
8,amazon.com
9,qq.com
10,twitter.com
top2
1,facebook.com
2,google.com
3,youtube.com
4,yahoo.com
5,baidu.com
6,wikipedia.org
7,live.com
8,qq.com
9,amazon.com
10,twitter.com
diff -u /Users/stofke/Desktop/top2a.csv /Users... |
You could also consider an approach using join since you want sorted output in the end. Like:
join -t, -j2 <(sort -t, -k2 file1) <(sort -t, -k2 file2) |
awk -F, '{n=$3-$2; if (n) print n, $1}'
| How can I show the number of positions lines have moved in diff output? |
1,428,576,601,000 |
I want to sync 2 directories (/src & /dst) to mirror all the files in both of them.
Here is a steps:
sudo rsync -vaP --stats /src /dst -> completed without errors
sudo rsync -vaP --stats /dst /src -> completed without errors
diff -rq /src /dst-> doesn't show any diffs.
du -s /src && du -s /dst shows different sizes ... |
Sparse files may be expanded on copy when the -S flag is not used. (Will make the destination take more space)
Hard links within the tree may be expanded to separate files on copy when the -H flag is not used. (Will make the destination take more space)
Filesystems may have different allocation sizes. A one-byte f... | rsync completed in both directions, but size of directories is different. How it's possible? |
1,428,576,601,000 |
I have some media files (right now it's video files, but I suspect I would also be able to use a good solution on picture files), that are very similar, but according to diff/cmp not identical. But if it's only a few bytes that differ I might not be able to tell the difference (I know that depends lot on several thin... |
The cmp program (unless you suppress its output with the -s option) lists the differing bytes. You could get a count by piping that into wc, e.g.,
cmp -l foo bar | wc -l
The -l option tells it to list all differences. To account for different lengths, you'd have to make a more complicated script, since cmp doesn't ... | How alike/different are two binary files |
1,428,576,601,000 |
I am mirroring a Subversion repository tag with svn2git and I want to be sure that when I checkout particular revisions, those I obtain from the git mirror match those from Subversion. My main problem is that subversion tags can be updated, and I need to ensure that checking out the matching tag in the git mirror, mat... |
diff -qrN is about as fast as it gets to compare two directory trees. The -q option makes it quit early when files differ. Since you expect the files to be identical most of the time, it doesn't matter all that much: the comparison tool has to read and compare the whole files anyway.
The only improvement you can make ... | What optimized tools are available for comparing directory contents? |
1,366,299,010,000 |
Sorry for such a simple question, but I can't figure this out for the life of me. Neither DISPATCH-CONF(1) nor wiki.gentoo.org/wiki/Dispatch-conf provide any instructions.
When running dispatch-conf:
The diff is output, e.g.:
--- /etc/systemd/resolved.conf 2021-06-09 19:50:06.087987199 +0200
+++ /etc/systemd/._cfg... |
I am sure this is documented somewhere, such as in dispatch-conf(1), but I will try to describe it quick. disclaimer: I had to check the manpage for t and l.
In the initial (second) screen with the prompt, here are what the actions do:
q exit from dispatch-merge without doing anything. This is always safe. You can re... | How do you merge files with dispatch-conf? |
1,366,299,010,000 |
I have two directories on two different hard drives and want to check if the content is really exactly the same.
From what I read I can use diff -rq dir1 dir2 to check if files are missing or differ.
-q,--brief
report only when files differ
-r,--recursive
recursively compare any subdirectories found
However as ... |
mtree(8) is an excellent tool for this:
The command:
$ mtree -cp path/on/hostA -K sha256 | ssh hostB mtree -p path/on/hostB
will report differences between the heirarchy in hostA:path/on/hostA and the heirarchy in hostB:path/on/hostB in terms of type, size, timestamp, permissions, and content. Additionally, missing ... | Compare content of two folders/disks (including timestamps,permissions) |
1,366,299,010,000 |
I use git on a regular basis for collaboration with other people. When we work together on a shared repository, I'd like to be able to view the changes performed by others which happened between my last commit and the current master branch (or the current HEAD).
Until now I'm using the following workflow:
git fetch ... |
This is not a very 'git like' way to approach the problem. Normally you would just keep a branch which pointed to your last commit.
However to answer the question, try the following helper function. This is not going to be very efficient, I probably need to user some lower level commands.
my_last_commit(){
loc... | Display git-diff between master and my last commit |
1,366,299,010,000 |
I have two directories A and B; each one contains a lot of sub-directories
geom001, geom002 ....etc
each sub-directory contains a file named results. I want to compare, without opening any of them, each file in A with each file in B and find if there is a file or more in A similar to one or more file in B.
How can I... |
If files are exactly the same, then their md5sums will be exactly the same, so you can use:
find A/ B/ -type f -exec md5sum {} + | sort | uniq -w32 -D
An md5sum is always exactly 128 bits (or 16 bytes or 32 hex digits) long, and the md5sum program output uses hex digits. So we use the -w32 option on the uniq command... | How can I compare different files without opening them? |
1,366,299,010,000 |
What is the list of programs that were available in the first public version of Linux distribution (not just kernel)? I am specially concerned when this distribution was released and if diff utility was there.
|
Short answer - it did.
A bit of archeology reveals that
The first linux distributions were published in 1993. SLS 1.02, linked above, was the most popular at the time.
GNU bulletin for Jan 1993 includes diff 2.0.
diff 2.0 GNU diff compares files showing line-by-line changes in
several flexible formats. It is much... | Was 'diff' included in the first version of Linux |
1,366,299,010,000 |
I'm trying to compare two directories that contain binary files, on AIX 6. I'm using diff in preference to dircmp, as I'm trying to maintain a consistent output format between this and my Linux servers, where dircmp is not available.
According to the diff man page,
If the Directory1 and Directory2 parameters are sp... |
There's a limit to how much portable code you can write without having conditionals to execute different things on different systems. Don't feel bad about using dircmp if available or GNU diff if available.
if type dircmp >/dev/null 2>/dev/null; then
dircmp dir1 dir2
else
diff -r dir1 dir2
fi
If you only want to ... | Comparing directories using diff |
1,366,299,010,000 |
Suppose I have same version of linux kernel but I changed some driver lines. Is there any way to compare these kernels and list the results. The result would be helpful to go back if I changed a lot in original drivers.
|
The traditional method:
diff -r dir1 dir2
That gives you a file-by-file difference, which can be kind of wordy. If you have Gnu diff,
you can try:
diff -r --brief dir1 dir2
| Compare two similar directories and list differences between files |
1,366,299,010,000 |
I want to apply a unified diff from mypatch.diff to stdin and output the result to stdout.
So far, I have tried:
patch -i mypatch.diff -o - -u originalfile
Which successfully applies mypatch.diff and prints the result to stdout. However, I still have to provide the original file as originalfile, not via stdin.
And if... |
It doesn't look like GNU patch has an option for that. - means stdin for -i or stdout for -o (and for -r is interpreted as discarding rejects) but for the file to patch - is interpreted as the file called - in the current directory.
Also, patch will want to create files with .orig or .rej suffix when relevant based on... | How to apply a patch as part of a pipe? In other words, how to patch stdin? |
1,366,299,010,000 |
I desire to compute the difference of two lists:
$ pip list > package1.md
Package Version
---------------------------------- ---------
alabaster 0.7.10
anaconda-client 1.6.9
anaconda-navigator 1.7.0
anaconda-project ... |
With comm command:
comm -23 <(sort package1.md) <(sort package2.md)
| Find the difference between two list |
1,366,299,010,000 |
I have a set of files in a structure like so;
regions
├── ap-northeast-1
│ └── sg-66497903
│ ├── sg-66497903-2017-10-03-Tue-12.39.json
│ ├── sg-66497903-2017-10-03-Tue-12.42.json
│ ├── sg-66497903-2017-10-03-Tue-12.49.json
│ ├── sg-66497903-2017-10-03-Tue-12.53.json
│ └── sg-66497903-20... |
It's a lot easier in zsh:
for sg in ~/region/ap-*/sg-*(/); do
files=($sg/sg-*.json(N.Om)) # list of json regular files sorted
# from oldest to newest
if (($#files >= 2)); then
oldest=$files[1]
files[1]=()
for file in $files; do
cmp -s $oldest $file ||
printf ... | list oldest file in directories in a loop |
1,366,299,010,000 |
dir1 has 1 file and dir2 has 2 files as below:
/tmp$ ls dir1
file1
/tmp$ cat dir1/file1
line1
line2
line3
/tmp$ ls dir2
file1 file2
/tmp$ cat dir2/file1
line1
/tmp$ cat dir2/file2
line1
/tmp$ diff -ur dir1 dir2 | diffstat
file1 | 2 --
file2 |only
2 files changed, 2 deletions(-)
I am looking for a command to ... |
You need to use the -N (treat missing files as empty) option to diff. For example:
$ diff -N -u -r dir1/ dir2/ | diffstat
file1 | 2 --
file2 | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
| git --diff like command for Linux local dirs |
1,366,299,010,000 |
I have two files and a shell script.
File 1:
Batman
Superman
John Snow
Jack Sparrow
Rob Stark
File 2:
Batman
Ironman
Superman
Spiderman
John Snow
Arya Stark
Jack Sparrow
Rob Stark
The hound
Script:
#!/bin/bash
sort ~/Desktop/file1.txt > ~/Desktop/fileA.txt
sort ~/Desktop/file2.txt > ~/Desktop/fileB.txt
diff -y ~/... |
There are various improvements you could make to your approach but, keeping everything the same, all you need is to add one more line to your script and then make the last line append (>>) instead of overwrite:
#!/bin/bash
echo -e "FileA\t\t\t\t\t\t\t\tFileB" > diff.txt
sort ~/Desktop/file1.txt > ~/Desktop/fileA.txt
... | Assign diff -y column names |
1,366,299,010,000 |
I get information of a certain set of files in my mail every day, which looks like this:
58623208 Sep 14 20:08 blbn_blfbe_drv
57904920 Sep 14 19:54 blbn_cycmn
55814208 Sep 14 06:02 clsa_Upd
38912000 Sep 14 19:12 cs_chgpp
41107456 Sep 14 19:17 csmRFbe
39403520 Sep 14 19:09 csmUAddAct
39235584 Sep 14 19:20 csmUAddSub
... |
I assume you have GNU date, with the -d option:
while read size mon day time filename; do
if [[ ! -f "$filename" ]]; then
echo "ERROR: no such file: $filename" >&2
else
filesize=$(stat -c %s "$filename")
if [[ "$size" != "$filesize" ]]; then
echo "ERROR: size mismatch: $file... | Comparing files and their properties |
1,366,299,010,000 |
I'm learning about diff/patch and I don't understand why the patch file created by the command sequence below doesn't create the file create_me.txt inside the Org directory when I try to apply it.
Creating a file
$ ls -R
Org Upd
./Org:
./Upd:
create_me.txt
$ diff -ruN Org/ Upd/ > Org.patch
$ cat Org.patch
diff -ruN... |
Your first patch, and the way you’re applying it, is asking patch to create a file named Upd/create_me.txt, not Org/create_me.txt: the full path is significant. When patch sees an entry dated at the epoch (170-01-01 00:00:00 UTC), it knows that that represents a non-existent file; if it’s the “start” entry, it knows i... | Using diff / patch to create a new file inside a directory |
1,366,299,010,000 |
I'm on OSX and running a diff command like this, to create side-by-side output:
$] diff -Bbwy --width=200 --suppress-common-lines file1.txt file2.txt > diff-output.txt
It outputs my diffs just fine, but it uses tabs for indentation of the output (alignment of the side-by-side middle line, etc). Additionally, the file... |
diff (options) <(expand -t4 file1.txt) <(expand -t4 file2.txt)will expand tabs in the input files to spaces,
assuming tab stops set every four columns.
Combining this with diff’s -t option should get you what you want.
| Any way to change the tab size of the diff command's output? |
1,366,299,010,000 |
I got a requirement where I need to compare two files wrt to each columns and write the corresponding difference in another file along with some identification showing mismatched columns. Pointing out the mismatched columns is my main problem statement. For example we have files like:
File 1
1|piyush|bangalore|dev
1|... |
Python 3.x solution:
diff_marked.py script:
import sys
file1_name = sys.argv[1]
file2_name = sys.argv[2]
with open(file1_name, 'r') as f1, open(file2_name, 'r') as f2:
f1_lines = f1.readlines() # list of lines of File1
f2_lines = f2.readlines() # list of lines of File2
for k,l in enumerate(f1_lines):
... | Comparing two files and writing mismatched rows along with mismatched columns. Pointing out the mismatched columns is my main problem statement |
1,366,299,010,000 |
I am trying to verify a backup that I made using the following command:
dd if=/dev/sda of=/dev/sdc2
I backed up the contents of /dev/sda (internal hard drive) to
/dev/sdc2 (external backup drive, connected via USB), however
/dev/sdc2 (the partition where /dev/sda is being backed up into)
is slightly larger than /dev/... |
Perhaps cmp is adequate in this case:
SYNOPSIS
cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]
DESCRIPTION
Compare two files byte by byte. (...)
-n, --bytes=LIMIT
compare at most LIMIT bytes
You will want to pass, as an argument to cmp -n, the size in bytes
of the source device, whi... | Compare two files, while overriding second file's size |
1,366,299,010,000 |
I have two text files with the same number of newline terminated strings. The lines in the two files correspond to each other. The lines in each file individually might be repeated.
I would like to quickly identify which two lines differ and output either from the first file or from the second one.
File A:
this is a s... |
This does the comparison from the perspective of fileA:
$ awk 'FNR==NR{a[NR]=$0;next;} $0!=a[FNR]' fileB fileA
this is a string
empty string
This approach reads the whole of fileB into memory. Thus, if your files are huge (too big for memory), you should choose another approach.
Similarly, to obtain the output from ... | Output different lines when comparing two files |
1,366,299,010,000 |
Is it possible to create a diff file that would work without having the actual files in the diff file?
e.g.: I have a folder /a and a copy of a: /b. In /b I edit multiple files and create a .diff file. I sent this file to someone else so they can use this file to update their /a folder.
I use the following to create t... |
The other person would just use patch, try first:
patch --dry-run -p0 < file.diff
You might need to adjust the -p option (or drop it) according to how you passed the folder parameters to 'diff' and from which folder you are applying the patch, check the patch manpage for more details. But usually -p0 will work just f... | Unified Patch: only use diff file |
1,366,299,010,000 |
When I want to compare a local file with a remote file, any of these usually works:
$ ssh remote cat file | diff file -
$ diff file <(ssh remote cat file)
However, sometimes (especially when the password is needed) they fail like this:
$ ssh remote cat file | diff file -
1,162d0
< ...
< ...
Password:
Here, diff doe... |
When you run ssh first:
ssh remote 'cat file' | cat
ssh gets your controlling terminal as stdin, so you can type your password in with no problems.
When you use bash's process substitution, stdin remains connected to the first command, and the subprocess's output pipe gets passed to the first command as an argument:
... | password problem when feeding a remote file into diff |
1,366,299,010,000 |
I have a directory sub1 with the following files:
$ wc -l *
5 file1.csv
5 file3.csv
1 file4.csv
In sub2, I have the following:
$ wc -l *
5 file1.csv
5 file2.csv
1 file3.csv
5 file4.csv
1 file5.csv
In the first directory, I might have files with added lines, which then go to the second dir. In this example, I might ... |
Here is a quick and dirty shell "one-liner" with example output:
$ join -j2 <(cd sub1; wc -l *) <(cd sub2; wc -l *) | awk '$2!=$3'
file3.csv 5 1
file4.csv 1 5
total 11 17
The total line is an artifact from the output of wc. It can be removed with another filter:
$ join -j2 <(cd sub1; wc -l *) <(cd sub2; wc -l *) | aw... | How to find files with same name but different line count in two directories? |
1,366,299,010,000 |
In my daily work, I only deal with unified diffs, so I would like to define the alias
alias diff='diff -puN'
in my .zshrc.
This alias is not respected when I use the shell from the vim command line mode, i.e., when I enter :!diff file1 file2. I believe this is because vim does not invoke an interactive shell.
Thus, I... |
Changing the semantics of the diff command indeed wreaks havoc on Vim (this is explained under :help diff-diffexpr: The output of "diff" must be a normal "ed" style diff. Do NOT use a context diff.), and potentially other programs, too.
A pure shell alias with the same name is fine, as that is only considered when yo... | Vim and unified diffs |
1,366,299,010,000 |
I have done a listing of the device folder two times, one time without the sd-card in the slot and one time inserted, the system automatically adds one
file in the device folder.
$ ls /dev | wc -l
205
$ ls /dev | wc -l
206
I could put each listing into a separate file: ls /dev > foo.
But how can I determine from th... |
You could run this before adding the device to store the inital list
in a file:
ls /dev >~/a
And then this after adding the device:
ls /dev | diff -u ~/a -
This should show you in what way the two lists of files differ. diff
shows the differences between two text files, and flag -u changes its
output format: lines a... | How to determine the only additional file in otherwise two identical listings? |
1,366,299,010,000 |
I have a machine running Ubuntu 6.06. Source files under rcs (no git available).
I need to visually compare older revs of files with the checked out version.
Until now I have moved the file and compared.
mv test.c tmptest.c
co -r1.16 test.c
xxdiff test.c tmptest.c
mv tmptest.c test.c
I know I can make this in a scri... |
You can extract the version to stdout with -p and then pipe into xxdiff:
co -p1.16 test.c | xxdiff - diff.c
| rcs and graphical diff |
1,484,807,103,000 |
I'm migrating to Linux, and I need to convert the following Windows cmd command:
fc file1.txt file2.txt | find /i "no se han encontrado diferencias" > nul && set equal=yes
I think fc can be replaced by diff or comm, find with grep, but I don't how to do the && part, maybe an if statement...
|
Taking a guess as to what those Windows commands do, I'd say the equivalent in a POSIX sh script would be:
equal=no
cmp -s file1 file2 && equal=yes
which would set the equal variable to yes if the two files can be read and have identical content (byte-to-byte).
As an alternative to cmp -s, on some systems including L... | Linux equivalent of windows cmd command |
1,484,807,103,000 |
Say I have a file foo and a file bar. I now call the following commands:
$ diff foo bar > diff_foobar
$ rm bar
Is there a(n easy) way to programmatically reconstruct the missing bar from foo and diff_foobar?
|
Yes, you apply the patch:
You did:
$ diff foo bar > diff_foobar
$ rm bar
Now do:
$ patch foo -o bar < diff_foobar
| Reconstruct file from diff |
1,484,807,103,000 |
I've recently made multiple images of several SD cards on multiple machines using dd. I haven't done a stellar job with my naming, and have some duplicates. How can I quickly determine if two images are equal? I've been using diff but it takes a while.
|
md5sum *.img | sort
Should make any duplicates obvious.
| Determine if two iso images are equal |
1,484,807,103,000 |
So I'm using etckeeper on my machine running Debian 9.1 with KDE and would like to view diffs (or if that isn't yet implemented: past versions) of specific files. How can I do that?
|
By default, with etckeeper, /etc is a git repository, so you can use git tools to view its contents (and the changes). For example, you can use gitk (after installing it) to browse the repository’s history, and if you want to focus on a specific file, you can specify it on the command line:
cd /etc
gitk apt/sources.li... | How can I view diffs or at least older versions of specific files with etckeeper? |
1,484,807,103,000 |
This answer shows how to diff two strings - Using the diff command to compare two strings?
I try:
diff <( printf '%s\n' "tring1" ) <( printf '%s\n' "string2" )
The output is:
1c1
< tring1
---
> string2
This shows that the two strings are different.
I would like to know at which characters the two strings are differe... |
For your specific use-case, store the strings in files, and compare those with git diff:
$ echo tring1 > f1
$ echo string2 > f2
$ git diff --word-diff --word-diff-regex=. --no-index f1 f2
diff --git a/f1 b/f2
index e8ae123..d704b3b 100644
--- a/f1
+++ b/f2
@@ -1 +1 @@
{+s+}tring[-1-]{+2+}
This shows that the “s” char... | Show differences in strings |
1,484,807,103,000 |
I have 2 files, each containing the same amount of 4-lines records, in the same order:
fileA:
record1 line1=header
record1 line2 X <= this is different but should be ignored
record1 line3 id ABC
record1 line4
record2 line1=header
record2 line2
record2 line3 id DEF <= this is different
record2 line4
fileB:
record1 lin... |
For your updated input, based strictly on 4-line records, you can use modulo arithmetic to maintain arrays of the current records, and check the 3rd lines for a match every 4th line:
$ awk '
{a[FNR%4] = $0; getline b[FNR%4] < "fileB"}
!(FNR%4) && b[3] != a[3] {
for(i=0;i<4;i++) print b[i%4]
}
' fi... | Compare every nth line in 2 files and save (asymmetric) context |
1,484,807,103,000 |
I want to compare two files(say A and B) side by side(vertically) in in Vim. I open one of those two files(say A) and as per this answer in this site issue a Ctrl+w v . Now both the panels are showing contents of file A. How can I see the contents of A in the left had side and B in the right hand side ? I am using Red... |
You can skip Ctrl+w v and just do:
:vert diffsplit <other_filename>
| How can I load the right hand pane of vim with a new file in linux? |
1,484,807,103,000 |
I need to diff two unsorted text files with the output marking every line as either old, new, or unchanged. The marks should appear at the beginning or end of the line, and there should be no other output apart from these marked lines.
For example, say we have the following two files:
old.txt
unchanged line one
uncha... |
GNU diff supports line formats as well as group formats:
$ diff --old-line-format='- %L' --new-line-format='+ %L' --unchanged-line-format='| %L' old.txt new.txt
| unchanged line one
| unchanged line two
| unchanged line three
- deleted line one
- deleted line two
- deleted line three
| unchanged line four
| unchanged ... | diff marking each line as old, new, or unchanged |
1,484,807,103,000 |
I have two large files consisting mainly of numbers in matrix form, and I'd like to use diff (or similar command) to compare these files and determine which numbers are different.
Unfortunately, quite a lot of these numbers differ only by sign, and I'm not interested in those differences. I only care when two numbers... |
Given your shell provided "process substitution" (likes recent bashes), try
diff <(tr '-' ' ' <file1) <(tr '-' ' '<file2)
1,2c1,2
< 21 0.0081318 0.0000000 0.0000000 0.0000000 0.0138079
< 22 0.0000000 0.0000000 0.0000000 0.1156119 0.0000000
---
> 21 0.0081318 0.0000000 0.0000000 0.0000000... | How to ignore differences between negative signs of numbers in the diff command? |
1,484,807,103,000 |
I have 2 lists, one containing all 32 bit IP addresses, and the other is a list of ip ranges and other IP addresses. I need to find if each IP within list A exists in any IP range or address in list B. The end result would be to display the addresses from list A that do not exists in list B.
This would be easy using ... |
This script does the trick on Linux/Bash. I'm not sure if it's bug-free. Comment if you want any explanation.
#!/bin/bash
# The script prints addresses from one file that are NOT
# in the ranges provided in another file.
# $1 is the file with addresses to check
# $2 is the file that holds the ranges
## in format x.x... | identify if IP addresses in list A exist within a list of IP ranges in list B |
1,484,807,103,000 |
If I have a patch file in the unified patch format like the example below, how do I add lines to it so that those lines are then added by the (applied) patch?
--- lao 2002-02-21 23:30:39.942229878 -0800
+++ tzu 2002-02-21 23:30:50.442260588 -0800
@@ -1,7 +1,6 @@
-The Way that can be told of is not the eternal Way;
-Th... |
Short: you don't do this.
Long: Here's why
A unified-diff is a script, using line-numbers and counts which tie-in to the content of the diff.
It's possible to manually make simple changes to this script (I do...), but
A unified-diff is mainly useful with the patch program, and
patch checks for consistency between the... | How do I add to a unified patch file? |
1,484,807,103,000 |
I want to debug like:
strace -fe open python /usr/bin/gnome-tweak-tool 2>>/tmp/hello.log
strace -fe open python /usr/bin/gnome-tweak-tool 2>>/tmp/hello2.log
Then use kdiff3 to compare both logs, but different pids will make this comparison useless:
So my question is there any option from strace to exclude such -f p... |
One could log the outputs of the different pids to different files via the -ff -o filename options:
strace -o foo -ff -e open perl -e fork
strace -o bar -ff -e open perl -e fork
and then compare the appropriate foo.<pidnum> and bar.<pidnum> files.
| Exclude PIDs when comparing strace output |
1,484,807,103,000 |
While comparing 2 fairly big directories using diff -rq ... I want to exclude certain file types like tar.gz or error_log.
How do I do that?
|
GNU diff has options for doing this (see manual page):
-x, --exclude=PAT
exclude files that match PAT
-X, --exclude-from=FILE
exclude files that match any pattern in FILE
The pattern in each case is a glob (* for any number of characters):
diff -rq -x '*.tar.gz' -x '*error_log' foo bar
See... | Diff command with file type exceptions |
1,484,807,103,000 |
I've downloaded a video via a website that forces a login. Thus, it knows my login.
If I run the following on it, I get results that I do not want to have:
strings video.mp4 | grep "my user name"
It always shows up in the video, regardless of the username used. That is, if I download video1 with user1 and video2 wit... |
In the general case, this could be difficult to do. But you are looking at a video. The simplest solution here would be that they placed it into a tag.
The first thing I'd do is examine the tags. If you have it, run mediainfo on the file. Do you see your username in the output? If so, it's just in a tag. You cou... | How to remove data that shows up from 'strings' on a file? |
1,484,807,103,000 |
Just started with diff command. Can you please explain me,
diff thin_provisionings_controller.rb thin_provisionings_controller.rb[211]
512,513d511
include ThinProvisioningsGraphModule
So does that says to delete lines 512, 513 and add 511?
As described by this article
http://lowfatlinux.com/linux-compare-file... |
Use diff -y, which stands for diff --side-by-side. It will show the output in two columns, one for each file. The columns will be in the same order you input the files on the command line.
| Diff command. Basic explanation |
1,484,807,103,000 |
I have 2 directories
$ tree dir{1..2}
dir1
├── file1
└── file2
dir2
├── file1
└── file2
I want to compare all files in dir1 with all files in dir2 using ansible
and print differences like this
output:
${file1} from ${dir1}:
diff content
${file1} from ${dir2}:
diff content
and it will loop through all files to print... |
For example, given the files
shell> ssh admin@test_11 ls -1 /tmp/dir[1,2]
/tmp/dir1:
file1
file2
/tmp/dir2:
file1
file2
shell> ssh admin@test_13 ls -1 /tmp/dir[1,2]
/tmp/dir1:
/tmp/dir2:
and the differences
shell> ssh admin@test_11 diff /tmp/dir1/file1 /tmp/dir2/file1
31,32d30
< User1:*:1002:1004:My User1:/home/Us... | ansible comparing all files in 2 directories and printing the difference |
1,484,807,103,000 |
So I have 2 folders with a lot of similar files, and the version is written in the filename, so what I wanna do is check if the beginning of the filename is the same (for example "sample-1.12" and "sample-1.13" should be treated as same). I just need to find files without a similar named file in the opposing folder.
T... |
You could use the ${a:|b} array-substraction operator:
dir1=/some/dir
dir2=/some/other/dir
a=($dir1/*[[_-]*(N:t)) # [t]ail of every file with at least one -, [ or _
b=($dir2/*[[_-]*(N:t))
a=(${a%%[[_-]*}) # strip [*, _* or -* suffix
b=(${b%%[[_-]*})
print -r in $dir1 and not in $dir2:
print -rC1 -- ${a:|b}
print -r... | How do I diff 2 folders by file name, but just the beginning of the file names using zsh? |
1,484,807,103,000 |
Here's my script:
#!/bin/sh
result=$((diff <(sort 1.txt) <(sort 2.txt)))
if [[ $result != "" ]]
then
echo ERROR
else
echo PASS
fi
I got an error when execute this script:
chk.sh: line 3: diff <(sort 1.txt) <(sort 2.txt): missing `)' (error token is "1.txt) <(sort 2.txt)")
What the reason and how to fix it?
|
A few points:
process substitution (<( ... )) and the extended test syntax [[ ... ]] is not available in sh. You need more advanced shells like bash or ksh for those.
$(( ... )) is arithmetic substitution, not command substitution. You need $( ... ) here.
Instead of checking the output of diff, you can check the exit... | how to execute compound commands in shell script? |
1,484,807,103,000 |
So, I've run the ls -C1 on two directories:
mod@ux:~$ ls -C1 /bin | wc -l
165
mod@ux:~$ ls -C1 /sbin | wc -l
167
How to list only different filenames/commands and which directory contains them?
|
Execute diff <(ls -C1 /bin |sort) <(ls -C1 /sbin |sort) |less.
With /bin and /sbin as input to the command above, diff will append < to files unique to /bin and > to files unique to /sbin. If you need the < and > to be more informative, you can use sed to replace them with more informative strings:
diff <(ls -C1 /bin ... | Diff filenames of two directories? |
1,484,807,103,000 |
I'm trying to build a scrip that compare a file inside different 2 dir,then
copy them from dir1 to dir2 is it's not exists in the dir2, or overwrite it if its already existed.
I know that i can use diff dir1 dir2 but then how do copy the result over to dir2. because diff command give me result like only in dir1: file1... |
rsync works locally and does tests on both file timestamps and file sizes.
rsync --archive /path/to/source/ /path/to/destination/
You may also use rsync on individual files.
| Compare existing file in two different directories, copy if not existent, else overwrite it |
1,484,807,103,000 |
I want to compare two UTF-8 encoded text file. Can Linux command diff and comm handle these encoding?
|
Why not?
2 text files in Russian
$ file -i test1.txt test2.txt
test1.txt: text/plain; charset=utf-8 ... | Can linux command comm handle UTF-8 encoded text files? |
1,484,807,103,000 |
I became curious when I was diffing two large (>326MB) files, and noticed that the second run took much less time than the first. This was frustrating, since I was trying to time the second run, to see how long the diff took. :)
The man page doesn't mention a cache, and searching for 'diff cache' seems to flood me w... |
diff isn't doing any caching. The OS is. If you are using Linux, you can flush the disk buffers and cache. See How do you empty the buffers and cache on a Linux system?
| How does the diff command handle caching? |
1,484,807,103,000 |
I have two directories with same files but with some difference in their contents. I want to list down those files which are differing. For example
There are two folders Folder1 and Folder2 with files file1,file2,file3,etc. file2 of Folder1 is not similar to file2 of Folder2.
So my command should list file2.
How can... |
You can compare directories with diff:
$ diff -qr dirA dirB
Only in dirB: file.txt
Files dirA/README and dirB/README differ
| Difference between files in directory [duplicate] |
1,484,807,103,000 |
I have a series of a few thousand files, all with filenames in order, so let's say file1.x, file2.x, file3.x, etc. All these files are in the same directory.
I know how to generate a diff from file1.x to file2.x, but is there a way I could write a bash script to generate diffs from one file to the next? Basically it w... |
The following script takes an argument like "file*.x" and applies it to find | sort to get a list of files to process. With thousands of files, you may get "too many arguments" by echo file*.x.
#!/bin/bash
prev=
find . -maxdepth 1 -type f -name "$1" | sort -V |
while read -r file; do
file=${file#*/} # Remo... | How do I generate diffs for a series of files? |
1,484,807,103,000 |
Before (or after) updating a package with apt-get update, how can I view the source code diff between the the new and the old version?
|
You can download the source code from the Debian repositories using:
apt-get source <PACKAGE>
It will download 3 files, a .dsc that describes the package, a .orig.tar.gz that contains the source code, and a .diff.gz that contains the changes.
This will work if in /etc/apt/sources.list/ you have included deb-src entrie... | Getting the diff of a package update |
1,484,807,103,000 |
This question is not about visual diff -- i.e. file comparison.
Is there a tool which let me compare directory A and B (recursively), and as the output I would get two panes, with lists -- files in A (as linear list, not a tree) that are missing in B, and in the second -- files in B which are missing in A.
And then I ... |
You can try Krusader (http://www.krusader.org/)
Cheers.
| Tool for visual directory comparison |
1,484,807,103,000 |
Background:
I use Obsidian to organize my notes as I study. It's an application which works "on top of" a collection of markdown formatted plain text files and then shows the links and connections between them graphically. The text files I stored within sub folders of a single folder
What I want:
Since I am studying f... |
This is literally a version control system that you're building there :)
Luckily, that is a problem that's already been solved. One of such tools is git (it's quite certainly also the most proliferate tool in that discipline).
I don't know obsidian, but assuming it doesn't even already come with some integration for g... | How to generate a list of daily changes to my notes? |
1,484,807,103,000 |
Let's say:
a is a 256 MB file containing random bytes
b is the same file except it has one additional leading byte 0
Thanks to this answer, I discovered that rsync is able to compute a "binary diff patch" between these two files:
rsync --only-write-batch=patch b a
In this example, the patch file is ... only 65 KB, ... |
Perhaps someone who knows this better can post another answer, but after further research, the key in rsync algorithm seems to be detailed in the paragraph "Determining which parts of a file have changed": Rolling hash.
Another useful reading: https://moinakg.wordpress.com/tag/rolling-hash/
vs. :
Another useful res... | How does rsync work in this simple example? |
1,484,807,103,000 |
I have two projects named project1 and project2 with identical file trees as follows.
project1/, project2/
.
├── src
│ ├── index.html
│ ├── main.js
│ ├── normalize.js
│ ├── routes
│ │ ├── index.js
│ │ └── Home
│ │ ├── index.js
│ │ └── assets
│ ├── static
│ ├── store
│ │ ├── cr... |
In a single line -- not a single command -- calling diff once for each:
while IFS= read -r filename; do diff project1/"$filename" project2/"$filename"; done < files-to-compare.txt
This reads the files-to-compare.txt file line-by-line, ensuring that nothing gets in the way of reading the entire line, then calls diff w... | How to see which files are identical given a list of files in two projects |
1,484,807,103,000 |
I'm currently attempting to change the contents of one file
orig.sas
to match the contents of an updated file
new.sas
Replacing orig.sas with new.sas makes some of the changes, but there are many directories referenced within orig.sas that I do not want altered.
Submitting the following code outputs a script 'cha... |
diff -e 's result is supposed to be feed (modified) to ed.
try
diff -e orig.sas new.sas > changes.txt
echo wq >> changes.txt
ed orig.sas < changes.txt
where
wq will write and quit, printing number of char written
optional --silent will not output above count.
see man ed for further information.
edit
I fail to see ... | Using output of diff -e with sed |
1,484,807,103,000 |
I would like to compare multiple local files with their counterpart on a remote host, so I'd like to create a script like:
ssh user@remote_host "cat remote_file1.txt" | diff - local_file1.txt
ssh user@remote_host "cat remote_file2.txt" | diff - local_file2.txt
...
ssh user@remote_host "cat remote_fileN.txt" | diff - l... |
One way is to set up passwordless access (public key authentication), the other is to multiplex the connections. Create a configuration file in ~/.ssh/config with the following:
Host remote_host
User user
ControlPath ~/.ssh/controlmasters/%r@%h:%p
ControlMaster auto
ControlPersist 5m
Create a directory ~/.ssh... | Run multiple diff between local and remote files |
1,484,807,103,000 |
I'd like to find files with the wav extension having the same filename, only different in extension (which is mp3) in the same directory.
I tried the following structured command so far:
$ diff -s $(for i in *.wav; do echo "${i%wav}"; done) $(for i in *.mp3; do echo "${i%mp3}"; done)
diff: extra operand `abc(xyz'
diff... |
If you want to diff the output of some commands, use process substitution <(...) instead of command substitution $(...). Otherwise that seems it should work.
diff $(foo) puts the output of foo on the command line of diff, while diff wants the name of a file to read. diff <(foo) arranges for the output of foo to be ava... | Compare two file listings to find identical files but ignore extensions |
1,491,882,661,000 |
I am comparing a list of packages for a Django project in production and development. There are inconsistency in versions, but I am only concerned about the packages that got installed independently on another. So I am trying to get lines that are not matched (noted with -----) in vimdiff.
I can whip a python or perl ... |
Returns only lines with unique first word:
cut -d ' ' -f1 input?.txt | sort | uniq -u
input1.txt:
package1 v1
package2 v1
package3 v1
package4 v1
package5 v1
input2.txt:
package1 v1
package2 v2
package4 v4
package5 v5
output:
package3
| How to get the unmatched lines in vimdiff |
1,491,882,661,000 |
I am trying to get the below output with the given input.
Can this be done with diff command? I am trying this syntax but not working:
diff -a --suppress-common-lines a.txt b.txt
Here are the two input files:
First a.txt:
abc abc/d_4.1/efg 35
xyz abc/d_4.1/efg 36
mno abc/d_4.1/efg 38
And b.txt:
abc abc/d_4/efg 35
... |
Utility diff has not an option to skip fields.
I tried to make it work with cut & uniq. Thought bellow will work, column 2 will be missing from the output.
$ cut -d/ -f1,3 file1 file2 |sort |uniq -u #column 2 is skipped
As a more correct solution i propose the following awk:
awk -F" |/" '{a=$1$2$4$5;seen[a]++;out[a]... | how to use Diff command ignoring text with in a line and get unmatched data based on condition |
1,491,882,661,000 |
Why does this give such output (both commands are supposed to do the same thing) and how can one make them give identical output?
diff <(cat some_file | gzip -c - | base64) <(gzip -c some_file | base64)
1,2c1,2
< H4sIACSOZFUAA2XNsRHAMAgDwDqZRkIQ8P6L+c5xnIL2m2c5E6BdIQA5cHPTaGTqlI3ki2jSoWrk
< e1Tw0PNSMT4KdPKfJgNiJT++AAA... |
gzip is encoding the filename of the input file into its output. Even with -c option it does this. You can see this with gzip -c some_file | strings|head -1. however, when reading from stdin, gzip does not do that, since it doesn't know the filename. You can tell gzip to omit from output the filename and time-stamp wi... | gzip files with cat and from pipe gives different results |
1,491,882,661,000 |
I have a script that uses diff -c then puts the output on a text file. What I want is to remove the line that does not have the "!" and display the lines with the exclamation mark. Is this possible? Can the cut command do the trick?
I wanted to use diff -c because it separates the files from directory1 to directory2.
... |
with grep:
diff -c file1 file2 | grep '^[-!*]'`
with sed:
diff -c file1 file2 | sed '/^[-!*]/!d'
| remove lines from an output file from diff |
1,491,882,661,000 |
I have several directories/web site resources, each has total size of several gigabytes. They are more than 90% the same. Sometimes only a few files are modified.
I need to download these files for backup purposes periodically. Storage space is no concern, but it is taking too long to download.
I would like to:
Use on... |
Consider deduplication. Is there anything that modifies those files directly on your server (instead of deleting and uploading something fresh)? If there is not, you could symlink or hardlink the identical files outright. That would save storage space on your server, and also automatically solve your download problem,... | Create a recursive diff directory. Copy reference and diff. Recreate original directory |
1,491,882,661,000 |
I'd like to print a list of lines where the first word in two files is identical, and the rest of the words are not. Some complicated mess with comm, grep and cut would be possible, but hopefully there's a simpler way.
Edit: I've managed to slap together some working code. Example tests:
$ cat file1
a 1 E
b 2 F
c 3 G
... |
Assuming that both file1 and file2 are sorted (otherwise join won't work):
diff -u file1 file2 |
grep -E "^[+-]($(echo $(join -o0 file1 file2) | tr ' ' '|'))"
Explanation:
The join command will output the join field that occurs in both files (i.e. the first word of the line which is the same in both files), one on ... | Diff similar lines |
1,491,882,661,000 |
I'm used to meld for editing while seeing an intra-line diff that's updated live in response to edits. One just types in the left or right pane of the window and then save one or both files.
I'm trying to use kdiff3 for the same purpose. I believe it does support live edits in the same style as meld, but I can't fig... |
Being stated that I would personally prefer kompare (latest update
2023-12-07) to kdiff3 (last version 2014-07-04) when looking for some diff utility well integrated to the kde-plasma desktop applications (dolphin in particular) unless still using kde4.
Anyway!
AFAIK meld displays only 2 panes, one for each diffed fi... | How to use kdiff3 to edit when comparing two files |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.