New answers tagged

0

You can use ANSI escape sequences. To set a color and style desired, there is a syntax \033[#m where # can be a valid set of semicolon separated numbers. You can define colors such as CLEAR="\033[0m" GREEN="\033[0;32m" BLUE="\033[0;34m" PURPLE="\033[0;35m" RED="\033[0;31m" YELLOW="\033[1;33m" And use them such as echo -e "${GREEN}Updated${CLEAR}" Check ...


2

To capture what I understand from the Q's comments, I'm going to answer that "no, it is not possible to do what you want with diff and patch", since they must include context, which includes content that you can't distribute. Given that you can't rely on ed to be present, if you can rely on sed to be there, then you could loop through your changed files ...


-1

At least with GNU diff, it seems to be possible with suitable LFMT (line format) specifiers: diff --new-line-format="replace line %-dn with:%c'\012'%L" --unchanged-line-format= --old-line-format= file1 file2 Tested with: $ cat file1 Hello, this is a file. It is pretty cool. I wrote it in a text editor. $ cat file2 Hello, this is a file. It is kinda ...


-1

diff file1 file2 | grep ^">" comes to mind


2

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 >/dev/null so -print in the first ...


2

You could find each file to be processed using find and feed each filename to a script made on purpose to look for a match and print the filename in case of a match; I'd suggest to use a script rather than a one-liner for the added easiness of handling the multi-line string compared to the prompt. That is: find . -name "*.[ch]" -exec /path/to/script {} \; ...


1

Is there any reason not to use git? It is really good at merging changes like these automatically, and is exactly what it's made for. This isn't directly an answer to the question, but an alternative solution. Using git instead of diff, it would look something like this: # copy your original code to a new folder cp -r 1.2.0 mysoftware_git cd ...


1

If git(1) gave the diff, you have to use git apply (git uses most of the diff(1) unified format, but adds some git-specific handling). If applying the patch fails, either (a) the patch got corrupted (i.e., lines deleted/mutilated, tabs expanded, different line ending conventions), or (b) you are trying to apply the patch to a different base (it should work ...


2

What you have is an output from git diff (not the usual diff command). You would not use the usual patch program to apply it. Instead, you would use a git tool "apply". Further reading: How to read the output from git diff`? git-diff - Show changes between commits, commit and working tree, etc git-apply - Apply a patch to files and/or to the index How ...


2

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. $ seq 10 15 > subset.txt $ seq ...


0

diff might not be the most suitable tool to do that. I would try to write a simple script which does specifically what you want. All in memory This is a very simple and generic solution. It loads the two files into minimalist memory structures, subtracts the records of subset.txt from the records of all.txt and writes out the remainder. #!/usr/bin/env ...


1

From what I could understand from your question, you just want to get the lines 2 and 3 from every file and output it into a new file. Here is a script to do so: find . -name "*.doc" | xargs awk 'FNR==2||FNR==3{print}' > new_file xargs will make awk process every file output by find. awk will print lines 2 and 3 from every new file it is supplied. In ...



Top 50 recent answers are included