date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,373,125,672,000
I have file a and b and I would like to output lines of b that changed since it was cloned from a. Just the modified lines, no surrounding context, no diff offset marks. How can I do that using shell scripting? (No Python/Perl/PHP/...) Sed and awk are acceptable solutions. For now, what I am doing is diff -y with --su...
With GNU diffutils package's diff this will output only lines from file b which either were modified or newly inserted: diff --unchanged-line-format= --old-line-format= --new-line-format='%L' a b
Diff, show modified line from right file only
1,373,125,672,000
I am trying to understand the linux diff command on two files whose lines are just permutation of each other but not able to grok the output that it generates. Consider the three commands below: [myPrompt]$ cat file1 apples oranges [myPrompt]$ cat file2 oranges apples [myPrompt]$ diff file1 file2 1d0 < apples 2a2 > a...
To understand the report, remember that diff is prescriptive, describing what changes need to be made to the first file (file1) to make it the same as the second file (file2). Specifically, the d in 1d0 means delete and the a in 2a2 means add. Thus: 1d0 means line 1 must be deleted in file1 (apples). 0 in 1d0 means l...
Result of diff two files with switched lines says missing the same line twice
1,373,125,672,000
I want to use cli tool for file comparison and need line-number before output line with which help I could jump to line difference, because I use tool which understands where to jump, if the line begins like this :line-number: regular line contents So I tried diff, and reading documentation seems like it might be poss...
Yes, it is possible. When using these options, the default is just to print out every line. This is very verbose, and not what you want. diff --unchanged-line-format="" will eliminate lines that are unchanged, so now only the old and new lines are produced. diff --unchanged-line-format="" --new-line-format=":%dn: %...
diff - output line-numbers
1,373,125,672,000
I've hardly ever used anything other than Meld. Can you recommend anything else? It would be extra nice if you give a reason for your recommendation (as a Comment). [note] I want an alternative because Meld has recently lost the feature to copy entire contents from one file to another. I'm referring to the functionali...
There are a number of tools that are usable: meld kompare -- diff file viewer kdiff3 -- file difference viewer Diffuse -- file difference viewer Do you have two files and want to view their differences? Use a "file difference viewer". Do you have a diff file and want to look at it in an easy-to-read display? Use...
Which GUI diff viewer would you recommend, with Copy-to-Left/Right functionality?
1,373,125,672,000
I installed php5-fpm package using apt; then I made some changes to the PHP configuration files. Now I would get the diffs between the original files versions (the ones of the package installed) and the current versions (modified by me). How to do it?
Try something like this: # exit on failure set -e package=php5-fpm mkdir $package cd $package # you could also get the file from a package mirror if you have # an older version of apt-get that doesn't support 'download' # or if you would like more control over what package version # you are downloading. # (e.g. ...
Get diff changes between original files installed with apt and current files
1,373,125,672,000
I have read about diff and patch but I can't figure out how to apply what I need. I guess its pretty simple, so to show my problem take these two files: a.xml <resources> <color name="same_in_b">#AAABBB</color> <color name="not_in_b">#AAAAAA</color> <color name="in_b_but_different_val">#AAAAAA</color> <col...
You don't need patch for this; it's for extracting changes and sending them on without the unchanged part of the file. The tool for merging two versions of a file is merge, but as @vonbrand wrote, you need the "base" file from which your two versions diverged. To do a merge without it, use diff like this: diff -DVERSI...
how to use patch and diff to merge two files and automatically resolve conflicts
1,373,125,672,000
According to https://www.computerhope.com/unix/udiff.htm The diff command analyzes two files and prints the lines that are different. Can I use the same diff command to compare two strings? $ more file* :::::::::::::: file1.txt :::::::::::::: hey :::::::::::::: file2.txt :::::::::::::: hi $ diff file1.txt file2.txt...
Yes, you can use diff on two strings, if you make files from them, because diff will only ever compare files. A shortcut way to do that is using process substitutions in a shell that supports these: diff <( printf '%s\n' "$string1" ) <( printf '%s\n' "$string2" ) Example: $ diff <( printf '%s\n' "hey" ) <( printf '%...
Using the diff command to compare two strings?
1,373,125,672,000
I'm making a minor change to a very large file image file (just a few pixels difference) which takes a long time to transfer over the network. Is there a way for rsync to identify the difference in the file and only send the small diff over the network?
rsync delta-transfer algorithm does this by default. Quoting rsync manpage: DESCRIPTION Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspec...
Can rsync update a large file that has only changed partially without full retransmission?
1,373,125,672,000
You've got three folders: folder current, which contains your current files folder old, which contains an older version of the same files folder difference, which is just an empty folder How do you compare old with current and copy the files which are different (or entirely new) in current to difference? I have sea...
I am not sure whether you can do it with any existing linux commands such as rsync or diff. But in my case I had to write my own script using Python, as python has the "filecmp" module for file comparison. I have posted the whole script and usage in my personal site - http://linuxfreelancer.com/ It usage is simple - g...
How do you compare two folders and copy the difference to a third folder?
1,373,125,672,000
git log -G<regex> -p is a wonderful tool to search a codebase's history for changes that match the specified pattern. However, it can be overwhelming to locate the relevant hunk in the diff/patch output in a sea of mostly irrelevant hunks. It’s of course possible to search the output of git log for the original string...
here https://stackoverflow.com/a/35434714/5305907 is described a way to do what you are looking for. effectively: git diff -U1 | grepdiff 'console' --output-matching=hunk It shows only the hunks that match with the given string "console".
Display only relevant hunks of a diff/patch based on a regexp
1,373,125,672,000
Saying that I have two files: a.txt and b.txt. The content of a.txt: hello world The content of b.txt: hello world something else Of course I can use vimdiff to check their difference, I can make sure that a.txt is a subset of b.txt, which means that b.txt must contain all of lines existing in a.txt (just like the e...
comm -1 -3 a.txt b.txt > c.txt The -1 excludes lines that are only in a.txt, and the -3 excludes lines that are in both. Thus only the lines exclusively in b.txt are output (see man comm or comm --help for details). The output is redirected to c.txt If you want the difference between the two files, use diff rather ...
How to write the difference between two files into a file
1,373,125,672,000
The diff implementation on OpenBSD has a non-standard -d option with the following documentation: -d Try very hard to produce a diff as small as possible. This may consume a lot of processing power and memory when processing large files with many changes. The GNU diff implementation has the s...
In GNU diff, also used on FreeBSD, the --minimal flag triggers an algorithm variation by Paul Eggert that causes it "to limit the cost to O(N**1.5 log N) at the price of producing suboptimal output for large inputs with differences". More specifically, it causes it to not apply several heuristics that deal in finding...
What effect does the "-d" option have with diff?
1,373,125,672,000
diff -u file1.txt file2.txt > patchfile creates a patch file which consists of instruction for patch to convert file1.txt to be exactly like file2.txt Can't this be done using cp command instead? I can imagine this to be useful for when the file is too large and has to be transferred over a network where this approac...
Diffs can be more complicated than just comparing one file versus another. The can compare entire directory hierarchies. Consider the example that I want fix a bug in GCC. My change adds a line or two in 4 or 5 files and deletes a handful of lines in those and other files. If I want to communicate these changes to...
Why use diff/patch when it is easier to just use cp
1,373,125,672,000
Is there a way to save the changes I made to my vim buffer as a patch file for the original file, without saving it as a separate file and using diff?
It's possible to do this without a plugin using the w command, so the buffer contents can be used in a shell command: :w !diff -au "%" - > changes.patch (% is substituted with the path of the file being edited, - reads the buffer from stdin)
How do I save the changes to my vim buffer as a patch file?
1,373,125,672,000
I have a large file composed of text fields separated by semicolons in the form of a large table. It has been sorted. I have a smaller file composed of the same text fields. At some point, someone concatenated this file with others and then did a sort to form the large file described above. I would like to subtract th...
You can use grep. Give it the small file as input and tell it to find non-matching lines: grep -vxFf file.txt bigfile.txt > newbigfile.txt The options used are: -F, --fixed-strings Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F ...
Tool in unix to subtract text files?
1,373,125,672,000
less itself isn't capable of doing syntax highlighting, according to this thread. However, git diff nicely shows colored output in less, its default pager. When I redirect the output of git diff into a file, no color escape sequences are visible. Does git diff know where it's being sent, and formats the output accor...
Git uses isatty() to check whether stdout is a tty: this is used to see if a pager must be used (pager.c) as well as colors (color.c).
Git pager is less, but what is causing the output coloring?
1,373,125,672,000
At work we do a nightly dump of our mysql databases. From day to day, I would guestimate that close to 90-95% of the data is duplicate, increasing as time goes on. ( Heck at this point some are probably 99% ) These dumps are where one line is a single mysql INSERT statement, so the only differences are whole lines, an...
Two backup tools that can store binary diffs are rdiff-backup and duplicity. Both are based on librsync, but above that they behave quite differently. Rdiff-backup stores the latest copy and reverse diffs, while duplicity stores traditional incremental diffs. The two tools also offer a different set of peripheral feat...
rolling diffs for storage of highly similar files?
1,373,125,672,000
This is the output of my patch command: Hunk #11 merged at 4184,4190. Hunk #12 merged at 4444. Hunk #13 merged at 4944. Hunk #14 NOT MERGED at 5106-5116. Hunk #15 merged at 5290. Hunk #16 merged at 5448. patch unexpectedly ends in middle of line Hunk #17 merged at 5608,5611. The command was patch -d ~/SOME_DIR -p1 --...
The message refers to Hunk 16. This GitHub discussion is probably related to your issue. It is about patch unexpectedly ends in middle of line messages because of CRLF (carriage-return, linefeed) issues when git generated diffs are used with patch. To quote the conclusion: [..] git can be very picky about line ending...
What does 'patch unexpectedly ends in middle of line' mean?
1,373,125,672,000
I have a number of files, I want to check that all those files have the same content. What command line could I use to check that? Usage could be something like: $ diffseveral file1 file2 file3 file4 Result: All files equals OR Files are not all equals
With GNU diff, pass one of the files as an argument to --from-file and any number of others as operand: $ diff -q --from-file file1 file2 file3 file4; echo $? 0 $ echo >>file3 $ diff -q --from-file file1 file2 file3 file4; echo $? Files file1 and file3 differ 1 You can use globbing as usual. For example, if the curre...
Diff several files, true if all not equal
1,373,125,672,000
I have a number of files in a directory, and I want to check that they are all unique. For simplicity, let's say I have three files: foo.txt, bar.txt and baz.txt. If I run this loop, I will check them all against each other: $ for f in ./*; do for i in ./*; do diff -q "$f" "$i"; done; done Files bar.txt and baz.txt di...
If you just want to check whether two files are identical or not, use cmp. To get an output only for identical files, you could use for f in ./*; do for i in ./*; do cmp -s "$f" "$i" && echo "Files $f and $i are identical"; done; done diff tries to produce a short, human-readable list of the differences, and this can...
Can I get the opposite of `diff -q` -- matching identical files without printing their contents
1,373,125,672,000
How do I create a list of modified files programmatically using linux command line tools? I'm not interested in the difference in any particular file (delta, patch). I just want to have a list of new or modified files comparing to previous product release. So that I can publish a new product update. update: diff -qr d...
I`ve got a simple approach for this: Use the rsync-preview mode: rsync -aHSvn --delete old_dir/ new-dir/ The files that are shown as "to be deleted" by that command will be the "new" files. The others that are to be transferred have changed in some way. See the rsync-man-page for further details.
linux diff tools: create list of modified files
1,373,125,672,000
I am trying to find a way to determine if a text file is a subset of another.. For example: foo bar is a subset of foo bar pluto While: foo pluto and foo bar are not a subset of each other... Is there a way to do this with a command? This check must be a cross check, and it has to return: file1 subset of file2 : ...
If those file contents are called file1, file2 and file3 in order of appearance, then you can do it with the following one-liner: # python3 -c "x=open('file1', mode='rb').read(); y=open('file2', mode='rb').read(); print(x in y or y in x)" True # python3 -c "x=open('file2', mode='rb').read(); y=open('file1', mode='r...
How to know if a text file is a subset of another
1,541,621,264,000
From diffutils' manual Next come one or more hunks of diff erences; each hunk shows one area where the files differ. Unified format hunks look like this: @@ from-file-line-numbers to-file-line-numbers @@ line-from-either-file line-from-either-file... If a hunk contains just one line, only its start line number app...
I suspect the first paragraph (of the two you highlight) attempts to explain from-file-line-numbers whereas the second one attempts to explain to-file-line-numbers. I’ll ignore the text, which is obscure, and explain how GNU diff implements unified diffs (addressing the title of your question). diff -u <(printf "a\nb\...
How shall I understand the unified format of diff output?
1,541,621,264,000
Let's say I have a 4 GB file abc on my local computer. I have uploaded it to a distant server via SFTP, it took a few hours. Now I have slightly modified the file (probably 50 MB maximum, but not consecutive bytes in this file) locally, and saved it into abc2. I also kept the original file abc on my local computer. Ho...
For the second application/issue, I would use a deduplicating backup program like restic or borgbackup, rather than trying to manually keep track of "patches" or diffs. The restic backup program allows you to back up directories from multiple machines to the same backup repository, deduplicating the backup data both a...
Diff of two similar big raw binary files
1,541,621,264,000
I have two files that essentially contain a memory dumps in a hex format. At the moment I use diff to see if the files are different and where the differences are. However, this can be misleading when trying to determine the exact location (i.e. memory address) of the difference. Consider the following example showing...
This could be an approach: diff <(nl file1) <(nl file2) With nl number the lines that diff recognizes the lines line by line.
Compare two files strictly line-by-line, without insertions or deletions
1,541,621,264,000
Normally diff and git diff show both the original and the modified line with - and + respectively. Is there any way, I can filter only to see the modified line? This would reduce the number of lines to read by a factor of 2 instantly. I was assuming git diff test.yml | grep '^+' | less -R and git diff test.yml | eg...
You can use --word-diff to condense the + and - lines together with the changes highlighted using red/green text and stop using grep all together. You can combine this with -U0 to remove all context around the diffs if you really want to condense it down further. This approch is better than using grep as you don't l...
diff to show only the additions in a changed file
1,541,621,264,000
I have 2 files containing a list of songs. hdsongs.txt and sdsongs.txt I wrote a simple script to list all songs and output to text files, to then run a diff against. It works fine for the most part, but the actual diff command in the script is showing the same line as being different. This is actually happening for m...
My guess is you simply haven't sorted the files. That's one of the behaviors you can get on unsorted input: $ cat file1 foo bar $ cat file2 bar foo $ $ diff file1 file2 1d0 < foo 2a2 > foo But, if you sort: $ diff <(sort file1) <(sort file2) $ The diff program's job is to tell you whether two files are identical a...
diff reports the same line as different in 2 files
1,541,621,264,000
So we all have the diff command installed by default. I certainly don't know how to use it well. But I would expect some reasonable default usage. Yet when I type diff file1 file2 I get ... a text ... which I have to parse in my head ... which is not helped by the fact that this is a weird combination of two texts, wh...
I fear that this answer will not satisfy you, but I think that you pose conflicting constraints. About diff But first I have to defend the classical diff tool: Its main purpose is to generate software patches that are supposed to be processed by machines on application. In addition, these patches are designed to be as...
Command-line diff tool
1,541,621,264,000
In a recent Ask Ubuntu question on checking whether some files have differing content, I saw a comment stating that, if the differing sections didn't matter, cmp would be faster than diff. This Stack Overflow answer concurs, giving the reason that cmp would stop at the first differing byte. However, GNU diff has the -...
Prompted by @josten, I ran a comparison on the two. The code is on GitHub. In short: The User+Sys time taken by cmp -s seemed to be a tad more than that of diff in most cases. However, the Real time take was pretty much arbitrary - cmp ahead on some, diff ahead on some. Summary: Any difference in performance is pure...
Is cmp faster than diff -q?
1,541,621,264,000
I can do diff filea fileb to see the difference between files. I can also do head -1 filea to see the first line of filea or fileb. How can I combine these commands to show the difference between the first line of filea and the first line of fileb?
If your shell supports process substitution, try: diff <(head -n 1 filea) <(head -n 1 fileb)
Compare the heads of two files in bash
1,541,621,264,000
Is there a convenient way to identify duplicate or near duplicate blocks of text within a file? I want to use this for identifying code duplication. It looks like there are specialty programs with this capability but I'm not looking to get that involved. I'm hoping there's a tool similar to diff that will can do a sor...
If doing the comparision line-by-line is acceptable, then the following will tell which lines are duplicated in file text and how many times each one appears: sort text | uniq -c | grep -vE '^\s*1 ' As an example, $ cat text alpha beta alpha gamma alpha beta $ sort text | uniq -c | grep -vE '^\s*1 ' 3 alpha ...
Identify duplicate blocks of text within a file
1,541,621,264,000
Will it be possible to use diff on a specific columns in a file? file1 Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 file2 Another 123 stuff1 Another 193 stuff2 Another 783 stuff3 Another 353 stuff4 output(Expected) Something 456 item2 Something 768 item3 Another 193...
awk is a better tool for comparing columns of files. See, for example, the answer to: compare two columns of different files and print if it matches -- there are similar answers out there for printing lines for matching columns. Since you want to print lines that don't match, we can create an awk command that prints t...
Using Diff on a specific column in a file
1,541,621,264,000
I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed. For instance, given the two files below: a.txt a b c d e f g h i j k l m n o p q r s t u v w x y z b.txt a B c d e f g h i j k l m n o p q r s t u v w x y z (the difference betwee...
Using wdiff: $ wdiff -3 a.txt b.txt ====================================================================== [-b-] {+B+} ====================================================================== The -3 or ---no-common option will remove words that are common between the two files and only show the differences. The ===.....
diff showing only differences inside line
1,541,621,264,000
SHORT VERSION (TL;DR) I have 2 small one-line files, seemingly identical : $ cat f1 f2 ./cconv.sh 100 EUR USD ./cconv.sh 100 EUR USD But they are not, there is a 1 byte difference in size : $ ls -l f1 f2 (...) 24 oct. 30 16:19 f1 (...) 23 oct. 30 16:19 f2 $ diff f1 f2 1c1 < ./cconv.sh 100 EUR USD --- > ./cconv.sh ...
c2 a0 is the UTF-8 encoding of the non-breaking space character. It usually looks like a regular space, but isn't recognized as whitespace by the shell. In a few keymaps, something like AltGr+Space, or Option+Space produces a non-breaking space. Which is amusing if your keymap also has e.g. the pipe character behind A...
Space not taken as an argument separator by shell script (could someone please explain that small file difference ?)
1,541,621,264,000
I have a bunch of files stored in various directories. They have been created at different times, but I need to check that their contents are the same. I cannot find how to do a diff on ALL files in one directory. Is this possible or is another CLI tool required?
If you don't need to compare them, and only need to know if they differ, you can just diff every file in the directory with any one of the files in the directory via a for-loop... for i in ./*; do diff -q "$i" known-file; done ...where known-file is just any given file in the directory. If you get no output, none of t...
Can you diff all files in one directory? [duplicate]
1,541,621,264,000
I try to make a patch as introduced here. Say I have two directories pp1(modified version) and pp0(clean version), I make a patch file pp0.patch with the diff command: diff -crB pp0 pp1 > pp0.patch The problem is if there is a file only in pp1, it won't be included into the patch. How to work around it? UPDATE: I f...
You should be able to do this using --new-file switch. Taken from diff man page: --new-file In directory comparison, if a file is found in only one direc- tory, treat it as present but empty in the other directory. Try this: diff -crB --new-file pp0 pp1 > pp0.patch
how to include a new file into a patch
1,541,621,264,000
I used diff --from-file to compare my Riak dev1 config to the three others. diff --from-file ~/riak/dev/dev1/etc/app.config \ ~/riak/dev/dev2/etc/app.config \ ~/riak/dev/dev3/etc/app.config \ ~/riak/dev/dev4/etc/app.config It shows the configs differ only in the port number setting (8091, 8092, 8093, 8094). It's hard...
Add the parameter --unified=0 to show the names of each file. The --unified part sets the output format to 'unified'. The unified format starts with the names of the files being compared. The =0 part hides the context lines. It makes the output easier to inspect visually. Rerun the original command with the new parame...
How to show names of files being compared?
1,541,621,264,000
I want to use Diff only to check if files and directories exist the same in two locations but NOT compare the contents of the files themselves, because that's all I need and a regular Diff just takes too long for the amount of data. How would I go about this? Is there some other Debian standard tool that can accompli...
You can't use diff for that. Why would your requirement be to use diff? Why do people always come to conclusions without having examined the possible solutions in detail? You could use diff -qr but that wouldn't be wise from a performance point of view if the only goal is to compare the directory structure as outlined...
Diff: only compare if file exists, not contents [duplicate]
1,541,621,264,000
I was about to diff a backup from it's source to manually verify that the data is correct. Some chars, like åäö, is not shown correctly on the original data but as the clients (over samba) interpret it correctly it's nothing to worry about. The data restored from backup shows the chars correctly, leading diff to not c...
Unix filesystems tend to be locale-agnostic in the sense that file names consist of bytes and it's the application's business to decide what those bytes mean if they fall outside the ASCII range. The convention on unix today is to encode filenames and everything else in UTF-8, apart from some legacy environments (most...
Same file, different filename due to encoding problem?
1,541,621,264,000
I want to check the results of a restore from backup. This is, because TimeMachine on MacOS gives me some weird errors and warnings and I want to make sure, everything is in its place again after restoration. While I don't trust TimeMachine to put every file back, I trust it to put every file it restores with the cor...
The "solution" you mention is a really bad one (it can't deal with weird file names for example) and completely unnecessary. Just use diff directly: diff -r "$PATH1" "$PATH2" That will recursively (-r) compare the directories and report whether files are present or missing. For example: $ tree . ├── dirA │   ├── file...
Compare directory trees regarding file name (and size and date) [duplicate]
1,541,621,264,000
When I set the -s parameter, diff also print files, that are different. diff -s $FIRST_FILE $SECOND_FILE
One possible solution may be: diff -s $FIRST_FILE $SECOND_FILE > /dev/null if [ $? -eq 0 ]; then echo "The files are identical" fi NOTE: It changed the question text.
Silent result with two identical files in diff: how to show them?
1,541,621,264,000
I have an assignment for school. One part of it is to check a file for changes and write these changes to a log file. So far I've found the diff command which could be helpful in my opinion. Let's say I have two files with content like this: file1 orange apple file2 orange apple strawberry If I use diff -c file1 fil...
diff -u may be what you need for your assignment. To take your example and using diff -u: michael@x071:[/home/michael]diff -u file? --- file1 2016-11-24 07:48:41 +0000 +++ file2 2016-11-24 07:48:57 +0000 @@ -1,3 +1,3 @@ orange apple -peach +strawberry A word of advice - RTM - or - Read The Manual. The...
What does an exclamation mark mean in diff output?
1,541,621,264,000
I have tried using the linux diff command in the past without much luck or patience. I usually end up using a GUI utility like DiffMerge or Kdiff. Recently I started trying to use diff again to compare files on remote systems via ssh, and I have found the -y / --side-by-side option to be very useful, but I still feel...
In no particular sequence: meld is a very nice diff program which does very nice diffs and three-way merges. git config --global merge.conflictstyle diff3 gets you three-way merge output for use with tools like meld. wdiff does word diffs, very nice if colored: wdiff -w "$(tput bold;tput setaf 1)" -x "$(tput sgr0)" -...
How can I get the most bang for my buck with the "diff" command?
1,541,621,264,000
I want to compare the contents of two directories, recursively, showing which files are missing from one or the other, and which files have different content. But I don't want output on the differences within the files, just whether they are different or not. There won't be any links to worry about. I hope this isn't ...
Usually this looks already good: diff -rq dirA dirB
Recursively compare directories with summary on different contents without examining file contents' differences
1,541,621,264,000
Looks like -u can take an extra number argument, but I don't quiet get the manual, It says, -u, -U NUM, --unified[=NUM] output NUM (default 3) lines of unified context Someone name an example please? I couldn't find a working one.
-u by itself outputs results in "unified" format the number just changes the number of neighboring lines included as context.
What does -u of diff really do?
1,541,621,264,000
What is the difference between Copied context output format and Unified context output format when taking a diff? diff -NBur dir1/ dir2/ diff -NBcr dir1/ dir2/
Apparently you've misread the manual. The -u flag is for unified context, not Unicode and -c is for copied context, not 'Context format': -c -C NUM --context[=NUM] Output NUM (default 3) lines of copied context. -u -U NUM --unified[=NUM] Output NUM (default 3) lines of unified context....
What is the difference between Copied context output format and Unified context output format while taking diff?
1,541,621,264,000
I have two files paper.tex and paper_suggested_changes.tex the latter is a modified version of the former with corrections. I need to go through the two files and choose which changes to accept or reject, how would I go about this?
Install an utility like Meld (there are other utilities for doing this, too, but I like Meld since it doesn't have KDE/GNOME dependencies) and use it for visually diffing/merging the files. Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled p...
Review changes in .tex files
1,541,621,264,000
In a Bash Guide for Beginners (sec. 3.2.1.2. Local variables) there is an example command which is supposed to list all of the local variables, that are not in environmental variables, or so I think: diff set.sorted printenv.sorted | grep "<" | awk '{ print $2 }' I believe I understand everything about this command e...
They're not expressions, they're filenames for files produced as follows: printenv | sort > printenv.sorted set | sort > set.sorted That's not clear from the documentation so your confusion is understandable! Note that you may need to help diff and grep by forcing them to treat their inputs as text (with -a); envir...
What is a *.sorted command and why doesn't it work in my bash?
1,541,621,264,000
I am initially producing two files which contain lists of URLs—I will refer to them as old and new. I would like to compare the two files and if there are any URLs in the new file which are not in the old file, I would like these to be displayed in an extra_urls file. Now, I've read some stuff about using the diff co...
You can use the comm command to compare two files, and selectively show lines unique to one or the other, or the lines in common. It requires the inputs to be sorted, but you can sort them on the fly, by using process substitution. comm -13 <(sort old.txt) <(sort new.txt) If you're using a version of bash that doesn'...
Compare two URL lists and print newly added URLs to a new file
1,541,621,264,000
I'm trying to create patch a file using diff tool.But facing an issues.The way I am doing is below. I've created one Directory named a and put original file in to it. a/original_file.c Now I have created other Directory named b and put same file with modified content in to it. b/original_file.c Now content of b/ori...
diff has more than one option related to whitespace. However, one is less useful for patches. The manual page gives an obscure hint, referring to both GNU: -B, --ignore-blank-lines ignore changes where lines are all blank -b, --ignore-space-change ignore changes in the amount of white space...
How to create a patch ignoring indentation differences in the code?
1,541,621,264,000
I want to get the correct number of lines in the output of diff(specifically with -y and --suppress-common-lines options). Using a simple wc -l does not work, because if both files end without a newline and their last line is different wc -l won't count the last line. Is there a simple and efficient solution to avoid ...
There is no newline, so wc -l is correct. Instead, you want to count the number of start of lines. One way to do it: $ diff -y --suppress-common-lines a b | grep '^' | wc -l 1
Get correct number of lines in diff output
1,541,621,264,000
I have three files containing a sorted sequence of numbers, one per line : file1 1 2 3 file2 1 3 4 file3 1 5 I want to "align" these three files side-by-side like the following : file1 file2 file3 1 1 1 2 3 3 4 5 I've tried with sdiff but it only works with 2 files
You could process each file and print a line with some character e.g. X for every missing number in the sequence 1-max (where max is the last number in that file), paste the results then replace that character with space: paste \ <(awk 'BEGIN{n=1};{while (n<$1) {print "X";n++}};{n=$1+1};1' file1) \ <(awk 'BEGIN{n=1};{...
Side-by-side comparison of more than two files containing numerical values
1,541,621,264,000
I'm trying to compare files on the root file system with a backup, and I'd like the comparison to work a bit like git or svn diff when a file has been added or removed - That is, display the full file diff. diff unfortunately just prints a No such file or directory message, which is not very useful. I couldn't find an...
With at least some versions of GNU diffutils' diff, you can use the -N flag to do that directly (although the documentation appears to say that only works for directory diffs). $ ls foo $ cat foo foo $ diff -u foo bar diff: bar: No such file or directory $ diff -uN bar foo --- bar 1970-01-01 01:00:00.000000000 +0100 +...
How to make diff print a full file diff when a file does not exist?
1,420,798,283,000
I've got two directories with similar file names but different extensions. Here's an example: DIR1: - IN89284.wav - OUT9920.wav DIR2: - IN89284.mp3 - OUT9920.mp3 I want to compare these directories but ignore the file extensions, so in that case they would be the same. How can I do that? I guess that I'd have to...
With zsh: diff -u <(cd dir1 && printf '%s\n' **/*(D:r)) \ <(cd dir2 && printf '%s\n' **/*(D:r)) (D) to include dot-files (hidden files), :r to get the root name (remove extension). Using globbing guarantees a consistent sort order. (that assumes file names don't have newline characters).
diff two directories, but ignore the extensions
1,420,798,283,000
I have two folders: ORIGINAL/ ORIGINAL_AND_MY_CHANGES/ My friend has a copy of ORIGINAL/. I would like to generate MY_CHANGES.tgz -- it should contain only new/changed files from ORIGINAL_AND_MY_CHANGES/ comparing to ORIGINAL/. So my friend can unpack it into his copy of ORIGINAL/ and get ORIGINAL_AND_MY_CHANGES/. Ho...
With rsync What you're doing is essentially an incremental backup: your friend (your backup) already has the original files, and you want to make an archive containing the files you've changed from that original. Rsync has features for incremental backups. cd ORIGINAL_AND_MY_CHANGED rsync -a -c --compare-dest=../ORIGI...
How do I save changed files?
1,420,798,283,000
Narrow-down of a patch problem I am trying to troubleshoot: Only two files, each with a size of 1 byte: file a (containing 'a') file b (containing 'b') and Goal is to make and then apply a patch that will change the value of 'b' to 'a'. Contents of Makefile are: patch: diff -u b a > b2a.patch patch ...
Make assumes that an exit code of 0 means success, anything else means failure. This is the standard convention used by almost all command-line tools. Unfortunately, diff is not one of those. Checking the GNU diff info page, and also the Single Unix Specification "diff" entry, 0 means no differences found, 1 means dif...
Why does diff fail when invoked from a Makefile?
1,420,798,283,000
I have a folder with subfolders that contains text files. Every now and then I run a script that makes a copy of that folder tree and then creates a new one with fresh info. After that, having the old version and the new version, I run diff to know what changed between the old version and the new, sending the output ...
Any decent editor is able to highlight diffs conveniently. You can generally persuade your editor by using the .diff extension, or by setting the filetype to diff otherwise.
Diff patch output saved to a file. How to see it syntax-colored?
1,420,798,283,000
Suppose that I have the two files with the following content: $ cat File1.txt Apple orange watermelon avocado lime $ cat File2.txt orange Apple lime watermelon avocado Basically, there is no difference, as both have same values. I am using the diff command: diff File1.txt File2.txt and it shows files are different...
Compare the sorted files. In bash (or ksh or zsh), with a process substitution: diff <(sort File1.txt) <(sort File2.txt) In plain sh: sort File1.txt >File1.txt.sorted sort File1.txt >File2.txt.sorted diff File1.txt.sorted File2.txt.sorted To quickly see the differences between sorted files, comm can be useful: it sh...
I want to compare values of two files, but not based on position or sequence
1,420,798,283,000
I'm trying to compute the difference between the output of two awk commands but my simple attempts at it seem to be failing. Here is what I'm trying: diff $(awk '{print $3}' f1.txt | sort -u) $(awk '{print $2}' f2.txt | sort -u) This doesn't work for reasons unknown to me. I was under the assumption that $() construc...
diff expects the names of two files, so you should put the two output on two files, then compare them: awk '{print $3}' f1.txt | sort -u > out1 awk '{print $2}' f2.txt | sort -u > out2 diff out1 out2 or, using ksh93, bash or zsh, you can use process substitution: diff <(awk '{print $3}' f1.txt | sort -u) <(awk '{prin...
Diff the output of two `awk` commands
1,420,798,283,000
I'd like to use diff as described here and in the documentation I see when I type man diff. However, when I type diff, what I get is this: ~ ❯❯❯ diff usage: git diff --no-index <path> <path> Similarly when I try to use diff, I get git errors because -rq is supported in man diff but not by git diff: ~ ❯❯❯ diff -rq ~/ ...
This seems to be from prezto defining a function overriding diff. It may well have a way of disabling that, but I don't know what it is (but ericbn does!). You have a few options: /usr/bin/diff or command diff will both run the diff command, rather than the function. unset -f diff will remove the diff function. You c...
What is causing `diff` to run `git diff`?
1,420,798,283,000
I have a file both locally and on server. I first try running rsync in "dry-run" mode, to see if there are some differences between the files: $ rsync -aP --dry-run [email protected]:/home/dir . [email protected]'s password: receiving incremental file list dir/myfile.txt This apparently means that the file dir/myfil...
rsync will report changes for permissions differences timestamp differences content (and filesize) differences In comments, @roaima pointed out that there is an option to give a summary of these changes, in the rsync manual page: -i, --itemize-changes output a change-summary for all updates You may find it us...
rsync claims different files, but diff does not?
1,420,798,283,000
Is there a command that compares a floppy disk image (e.g. a .iso file) to the actual contents of the floppy the image was written on (e.g. /dev/fd0)?
A floppy device file is a file. Any command that reads files will work on it. cmp /dev/fd0 image.fat Pass the -l option if you want a list of all differing bytes; for human consumption, this is mostly useful in the form cmp -l /dev/fd0 image.fat | wc -l to know how many bytes differ. Run cmp -s /dev/fd0 image.fat if...
How do I compare a file with a floppy image and the actual floppy's content?
1,420,798,283,000
Is there a way I can diff a gzipped tarball against an existing directory? I would like to be able to do it without extracting the data from the tarball.
Mount the tarball as a directory, for example with AVFS. Then use diff -r on the real directory and the point where the tarball is mounted. mountavfs diff -r ~/.avfs/path/to/foo.tar.gz\# real-directory On GNU/Hurd, the equivalent would be tarfs.
diff a gzipped tarball against a directory?
1,420,798,283,000
I have a couple of questions about comparing text files on Emacs I have been playing with M-x compare-windows and I read in the documentation that, if I pass it a numeric argument, Emacs ignores whitespaces on the comparison, but how do I pass a numeric argument to this command? (e.g.. if I type M-x compare-windows ...
To pass a numeric argument to a command, enter the argument first. For example, Escape 3 Left moves 3 characters left. So type ESC 3 ESC x compare-windows RET or M-3 M-x compare-windows RET. The most frequently used commands to compare two files are those of ediff. You can invoke them from the “Tools > Compare (Ediff)...
Comparing text files on Emacs
1,420,798,283,000
Can patch be invoked with idempotency; i.e., is there some combination of options that will cause repeated invocations of patch to have the same effect as a single invocation of patch (for a non-empty diff)?
Some patches¹ can be applied multiple times, so this can’t be guaranteed; but patch -N -r- -i your.patch will apply your.patch, ignoring any hunks which have already been applied. -N avoids trying to revert an already-applied patch, and -r- skips saving failed hunks to .rej files. The equivalent command with long opt...
Can `patch` be idempotent?
1,420,798,283,000
I would like to compare two files - "orienv" and "currenv", using the command diff. The way I had created the two files was as follow: Createing the "currenv" file $cat /proc/1/environ >> currenv $cat /pcoc/279/environ >> currenv $cat /proc/295/environ >> currenv //295 is the pid of the current console Creating the ...
/proc/*/environ are not text files. use strings: strings /proc/{1,279,295}/environ >> currenv env > orienv diff -u orienv currenv
Diff outputs "binary files <file1> <file2> differ" but not the usual detail output
1,420,798,283,000
I have the next problem: Directory Example1 has three files: Example1, Things and Pictures. Directory Example2 has three files: Example2, Example3 and Pictures. I need a list showing only the files that match the directory name, this is: Example1 and Example2. I have tried with diff, find, locate and ls... but I have...
Since there are generally fewer directories than files, let's look for all directories and then test whether they contain the required filename. find . -type d -exec sh -c ' for dirpath do filepath="$dirpath/${dirpath##*/}" [ -f "$filepath" ] && printf "%s\n" "$filepath" done' sh {} + This wou...
Find files that have the same name as the directory
1,420,798,283,000
Is there a way to pipe the diff output into patch? The -i parameter is for specifying a diff file, but I just want to do it more dynamically, since I will be updating regularly against a directory that changes frequently. For instacne, something along the lines of patch -b | diff -Nub . /current-files ? The man fi...
Don't you want the other way around? diff -Nub . /current-files | patch -b
Pipe diff file into patch?
1,420,798,283,000
I created a backup on an external hard disc. Then I created another backup and copied all files to another external hard disc. I wanted to check with diff if everything was copied: user@user:/media/user$ diff -r backup backup1 Nur in backup1/home/user: file.xls. Nur in backup1/home/user: file.zip. ("nur" is German fo...
The output of diff -r with a German locale adds a . to the file. Files backup1/home/user/file.xls and backup1/home/user/file.zip should exist. Example: $ mkdir dir1 dir2 $ touch dir1/foo $ LANG=de_DE.UTF8 diff -r dir1 dir2 Nur in dir1: foo. $ diff -r dir1 dir2 Only in dir1: foo
diff shows a file that does not exist
1,420,798,283,000
Is there a tool (or diff option combination) which would produce output similar to git diff --stat? I have two kernel sources and I would like to get general idea of what was changed in them. Displaying all the changed lines is a overkill, I would like a simple file_name1 <number of changes> file_name2 <number of ch...
Yes, use Tom Dickey's diffstat: diff -ur dir1 dir2 | diffstat You can summarise any (well, most) diffs / patches with it, not just directory diffs.
Diff of directory statistics sumarry (git diff --stat like for non-git repo)
1,420,798,283,000
Given this diff command: ./a.out < 1.in | diff - 1.out What does - mean after the word diff? Thanks for the help!
Traditionally, - means stdin (standard input). As you're redirecting, the output of the first command is the input of the second.
What does dash "-" mean in Unix command line? [duplicate]
1,420,798,283,000
I use the vim-fugitive plugin to check git diff. The coloring scheme to highlight the code changes does not compliment my solarized background. I am not able to see the commands to change the coloring scheme of Gdif. Could anyone help me changing the coloring scheme?
From some poking around in :h diff |hl-DiffAdd| DiffAdd Added (inserted) lines. These lines exist in this buffer but not in another. |hl-DiffChange| DiffChange Changed lines. |hl-DiffText| DiffText Changed text inside a Changed line. Vim finds the first character that is ...
How to change the coloring scheme of Gdiff in vim-fugitive plugin?
1,420,798,283,000
The old diff, patch, and merge programs, and their modern descendents in the form of version control systems work great for managing source code that can be edited concurrently by multiple people. They are, however, strictly line oriented, and thus tend to fall down flat on text that is more free form. In my particul...
Wiggle (git://neil.brown.name/wiggle) can do this, and has a Debian package
merge that works at word granularity instead of line
1,420,798,283,000
I have $a and $b. I want to run diff on those. The best I have come up with is: diff <(cat <<<"$a") <(cat <<<"$b") But I have the district feeling that I am missing a clever Bash syntax to do that (as in "Why don't you just use foo?").
echo. Clearly less weird. #!/bin/bash a="`seq 10`" b="`seq 0 11`" diff <(echo "$a") <(echo "$b")
Elegant way of diff'ing two variables?
1,420,798,283,000
Example: % diff "/Volumes/New Volume/4kyoutube/" "/Volumes/New Volume/tmpmusic"| grep Distortion Only in /Volumes/New Volume/tmpmusic: ZAC & Bäkka - Distortion (Original Mix) [Sprout].mp3 Only in /Volumes/New Volume/4kyoutube/: ZAC & Bäkka - Distortion (Original Mix) [Sprout].mp3 % diff "/Volumes/New Volume/tmpmusic/...
This is not a "diff false positive", but rather the two file names are seen as different. My wild hypothesis is that either the two folders are on different devices, with a different file encoding; or that the two names are encoded differently albeit they are visually identical. Specifically, one of the two "Bäkka"s i...
diff program gives false positive for files with non-ASCII characters in filename
1,420,798,283,000
In Emacs, how do I inspect what has been modified in a buffer (before saving and overwriting the file)? (In a sense, the requested action is an analog of git status and git add -i showing what has been modified, only the comparison should be done between the buffer contents (in Emacs's memory) and the file on disk.) S...
M-xdiff-buffer-with-file I've just found it by looking through files.el where I felt there is such a command: View the differences between BUFFER and its associated file.
In Emacs, how do I inspect what has been modified in a buffer (before saving and overwriting the file)?
1,420,798,283,000
I used diff to produce a patch file. diff old.txt new.txt: 1c1 < Lorem ipsum dolor sit amet, consectetur adipiscing --- > The quick brown fox jumps over the lazy dog. The output is in the default "normal diff" format. Can I write comments in this patch file? If so, will the patch file be reasonably portable?
patch ignores lines that don't look like diff-output until it finds a chunk which matches that syntax. This is reasonably portable: existing implementations do this. The patches which I construct (e.g., using diff-patch) for ncurses and xterm all have a preamble giving the diffstat, prefixing the lines with "#" to m...
Can I write comments inside a "normal" diff/patch file?
1,420,798,283,000
I'm trying to write a script to get info from 5 different places and compare them for differences. The information is simply IP addresses and I have them placed in text files. I'm using: diff --from-file file1 file2 file3 file4 file5 to compare them and it works, but I need to display which file contains different ...
If you change the diff format to unified with -u or --unified, the filenames will appear. # diff -u --from-file file1 file[2-5] --- file1 2020-10-30 11:02:22.223269990 +0200 +++ file3 2020-10-30 11:02:35.445984702 +0200 @@ -1 +1 @@ -original +new --- file1 2020-10-30 11:02:22.223269990 +0200 +++ file5 2020-10-...
How to display which file differs from the others
1,420,798,283,000
I'm trying to add the transparency patch to dwm. I downloaded the .diff file and in my dwm directory ran this: max@linux-vwzy:~/misc/dwm/dwm-5.9> patch < dwm-transparency.diff patching file config.def.h patching file dwm.c Hunk #1 FAILED at 58. Hunk #5 succeeded at 306 (offset 1 line). Hunk #6 succeeded at 847 (offse...
The patch is failing because the other patches that you have previously applied have shifted the code around sufficiently to defeat patch's attempts to apply the change, even with an offset (as can be seen in those hunks that did succeed). If you open dwm.c.rej you will see the failed hunks, then it is just a matter o...
Patching a file (in this case dwm) and failed hunks
1,420,798,283,000
Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines. So I know pcregrep can do multi-line search. But you need to put the whole expression in. As this is a long paragraph I'm searchin...
Since you're trying to match the first 30 lines of your files you could save the text in a file e.g. ref_file then use diff to compare the reference file with the first 30 lines in each file: find . -name "*.[ch]" -exec ./myscript {} \; -print where ./myscript is #!/bin/sh head -n 30 "$1" | diff - /path/to/ref_file ...
Search directories for multi line string
1,420,798,283,000
Let's say I have two folders: before and after. ./before: bash ./after: bash The bash in the before folder differs from the bash in after. Using bsdiff or a similar program, is there a way to create a binary patch between the two folders? The program does not have to support Windows. New files in the after director...
The xdelta program does exactly what you are looking for: Name : xdelta Description : Xdelta (X for XCF: the eXperimental Computing Facility at Berkeley) is a binary delta generator (like a diff program for binaries) and an RCS version control replacement library. Xdelta uses a binary file delta algorith...
Binary diff of two folders
1,420,798,283,000
I have two files, all.txt (525,953,272 records) and subset.txt (525,298,281 records). Each record is nothing but a 17-digit ASCII integer. Both files have been sorted, and duplicate records within each file have been removed. Every value in subset.txt also exists in all.txt. I wish to find the records in all.txt that ...
Can anyone speculate on what might be going on, and whether there are arguments to diff that might help? Is this just not what diff was meant to do, and is there a different approach I should use? This is not what diff was meant to do; when the inputs have been sorted (as your have), the tool for the job is comm...
diff consuming huge amount of memory and cpu
1,384,262,383,000
Let's say I have a folder Documents and a TAR file Documents.tar, how to check if the tar file contains the same files that are present in the directory? The more obvious solution to me would be to do: $ tar xvf Documents.tar -C untarDocs $ diff -r Documents untarDocs Unfortunately this is very slow for large TAR fi...
If you want only to compare lists of file- and directory-names, the -d option is not helpful. Instead, diff'ing sorted lists from find and tar -tf would do that. Starting with the names assumed in OP's original example: $ tar xvf Documents.tar -C untarDocs $ diff -r Documents untarDocs here is a suggested script to ...
How can I check if a directory contains the same files of a TAR archive?
1,384,262,383,000
I have been using the below code ok for some time, but now I get an error java Editor < "input/editor$i.in" > "tmp/editor$i.out" diffCurr="$(diff "tmp/editor$i.out" "output/editor$i.out")" if [ -n $diffCurr ] Error (occurs on last line of above snippet): [: too many arguments What's wrong? I am trying to test that...
There's no need to put the output of diff in a variable, since you can tell whether files differ based on the exit status of diff, e.g. if diff -q file1 file2 >/dev/null 2>&1; then # files are equal else # files differ, or an error occurred fi diff returns success (0) if the files do not differ. Adju...
Error with if [ -n $diffCurr ]: Too many arguments
1,384,262,383,000
I've never patched anything in Linux, and I can't exactly figure out what the guy who wrote this post (second paragraph) means. That target source is qemu from github and the changes to apply are: diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 58f679e..c13a201 100644 --- a/linux-user/flatload.c +++ b...
This is actually a very short diff command. It says to remove the line //#define DEBUG and replace it with #define DEBUG. In this diff format, lines starting with a single - are removed and those with + are added. The other lines are for context, and the @@ tells the offset into the file and number of lines referenced...
Applying a diff patch
1,384,262,383,000
Are there any Kompare-like tools without KDE dependencies? Can be Qt or GTK based.
Try meld. It depends on Python and some GTK libraries but not much else. From its web page: Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support ...
Kompare-like tool that needs no kdelibs dependencies?
1,384,262,383,000
Consider for example a source code file, where the functions are drastically shuffled around. Is there is a command to check if the reordering of lines is the only change? (that means no lines are added, removed or changed)
The simple answer is: "compare the sorted version of both files". In bash: diff <(sort file1) <(sort file2) Obviously, this does not mean the two files have the same semantic as source files of a programming language (supposing are both syntactically correct).
How to determine if file is just a permutation of another one?
1,384,262,383,000
This is a basic question regarding bash but I could not find a solution. I have many subdirectories with identically named files and I want to compare all of them for identity. I can return list of this files with find . -name "protein.mol2" I know that file can be used as query in diff diff -q --from-file dir1/file ...
The --from-file option allows you to compare one file against many files (rather than something like tar --files-from which reads a list of files to operate on from a file). It has an analogous --to-file, which of the two you use would depend on relative "direction" of the change. Since you're using -q which only says...
How to pipe output of find as input for diff?
1,384,262,383,000
I have two files with thousands lines. I want to get their differences ratio in lines/bytes using diff, vimdiff or other commands, even regardless of the specific differences.
There's a tool called diffstat that sounds like what you're looking for. $ diff <file1> <file2> | diffstat Example $ diff afpuri.c afpuri1.c | diffstat unknown | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) This can be used for diff output which inclu...
How can I get difference ratio using “diff” or other command?
1,384,262,383,000
Is there a way to compare two file and give some kind of numeric indication of their similarity? For example, if I have two files that differ by just one character (say, a character was deleted or changed), the program ought to say something like "file X differs by 1 character." Or if two lines are different, say "fil...
One approach could be to compute the Levenshtein distance. Here using the Text::LevenshteinXS perl module: distance() { perl -MText::LevenshteinXS -le 'print distance(@ARGV)' "$@" } Then: $ distance foo foo 0 $ distance black blink 2 $ distance "$(cat /etc/passwd)" "$(tr a b < /etc/passwd)" 177 Here's a line-base...
Compare files and tell how similar they are
1,384,262,383,000
Whenever I am upgrading one of my Linux boxes (i.e. installing the next version of my favorite distribution), upgrading the respective configuration files always has been very time consuming, because in many cases I don't just alter the distribution's default configuration files to reflect my situation, but I have cra...
Man pages, once changed to a human-readable form, are text files that you can diff with whatever tool that suits you. Here are two examples, as two bash functions, for two tools: diff and vimdiff. Adapt them to your favorite tool. With vimdiff: vimdiff_man() { vimdiff -R <(man --manpath="/old/path/to/man" "$1") <(man ...
How to view differences between the man pages for different versions of the same program?
1,384,262,383,000
I have two bash arrays, say: arr1=( 1 2 3 ) arr2=( 1 2 A ) and I want to compare them using diff. How could I pass the arrays as if they were the contents of a file? I tried a few variations, but all failed: diff -y <$( echo ${arr1[@]} | tr ' ' '\n' ) <$( echo ${arr2[@]} | tr ' ' '\n' ) diff -y <${arr1[@]} <${arr2[@]...
Using printf and process substitution diff -y <(printf '%s\n' "${arr1[@]}") <(printf '%s\n' "${arr2[@]}") 1 1 2 2 3 | A
Pass BASH array to diff like file contents
1,384,262,383,000
How does one go about using diff to compare the output of two commands? I know how to use it to compare the contents of a file filename1 with the output of a command cmd2: cmd | diff filename - How do I make it so that I can have another command, say cmd1 in place of filename? I'm using dash, which doesn't support pr...
Based on How to emulate Process Substitution in Dash? (thanks αғsнιη!), adjusted for dash: ( cmd1 | ( cmd2 | ( diff /dev/fd/3 /dev/fd/4 ) 4<&0 ) 3<&0 )
Using diff to compare the output of two commands
1,384,262,383,000
I tried using this command to compute number of lines changed between two files: diff -U 0 file1 file2 | grep ^@ | wc -l My problem with this command is that if one file has only one line, and the other file has 100 lines, the output is still just 1. What command would give me the total number of lines changed, incl...
Looking for lines starting with @ gives you the number of blocks of changes that diff found. They would often be more than one line. As it happens, there's a tool to count the statistics of a diff: diffstat (web site, man page). Count insertions and deletions: $ diff -u test1 test2 | diffstat test2 | 3 +-- 1 file...
Given two files, how do I find the total number of line changes?
1,384,262,383,000
I'm trying to compare the file systems among many other basic services, before and after server reboot to check if any mismatches are present. I'm currently saving the data to a file and am comparing using diff command As there are many servers this is not being effective, as this is also checking the difference in t...
Is there a way to ignore the tabs - Size; Used; Avail; Use%; The df command output fields are adjustable via --output option: df -h --output='source' The above will output only filesystem names list Filesystem /dev/mapper/vg00-lvroot --output[=FIELD_LIST] use the output format defined by FIELD_LI...
Ignore changing size of "df -h" while using diff
1,384,262,383,000
Is it possible to apply patch to different file name but with the same structure. The case was, I have a patch of a file with specific name and then for some inevitable reason that file got changed and duplicated into multiple files but I have to apply the patch to all of that files, besides that I'm not allowed to re...
You can specify that the patch is to be applied to a specific file: patch -i main.patch main_cli.cpp Then, it's simple enough to loop over all the files: for f in main_*.cpp; do patch -i main.patch "$f"; done Example: $ diff -u bar foo > patch1 $ cp bar bar2 $ patch < patch1 patching file bar $ patch -i patch1 bar2 ...
Apply patch to multiple different name
1,384,262,383,000
I know I can specify external diff command to be used for git diff: [diff] external = But then when I am logged in console (without X) this fails because my visual diff cannot open display (obviously) How can I tell git to only use visual diff only when logged in GUI/X ?
You asked for an answer drawing from credible and/or official sources so I'm going to cite some official documentation in this answer. First, we need to find a way to determine if we're running inside X session. We could do that for example by checking if $DISPLAY variable is set. As it's described in man X: DISPLA...
git: use visual diff (meld) only when in GUI
1,384,262,383,000
I am having a large number of output files produced by repeated runs of a test suite and would like to see, approximately, how different they are. Ideally they should all be identical (indicating a fully reproducible test) or nearly identical (e.g. if timestamps are present). So I am looking for a script like: show-gr...
How about something like mostdifs=-1; for f1 in path/to/files/*.out; do for f2 in path/to/files/*.out; do difs=$(diff "$f1" "$f2" | wc -l); [ "$difs" -gt "$mostdifs" ] && mostdifs=$difs && mostdif="$f1 : $f2"; done done echo "$mostdif" This is very simplistic, you could improve it by test...
heuristically find how different a set of files are
1,384,262,383,000
Is there any standard option to create 'patch' P that works on file F in such way that it will keep working correctly when file F changes into F'. So I will either have some mechanism that will change P into P' so that P'(F') produces the same change as P(F), or, preferably, I will have resilient P so that it can be ...
This problem is known as merging. You have an original file A and two modified versions B and C, and you want to make a version D that combines both modifications. This only works if the changes are independent; otherwise, merging is a manual process. Handling merges of concurrent changes to source code is a frequent ...
Keep patch in sync with changing source
1,384,262,383,000
Lets say I have two lists: guests-2016.txt: Peter Michael Frank Dirk guests-2017.txt: Mark Michael Dirk Lilly How may I create two new lists of guests Guests that were in guests-2016.txt but are not in guests-2017.txt (former_guests.txt) Guests that were not in guests-2016.txt but are in guests-2017.txt now (new_gu...
Given two sorted files, comm would do this for you. See the combinations of the -2 -3 and -1 -3 command line options, for example.
Bash Script for showing difference between two text files