Tag Info

New answers tagged

0

I don't think diff (even in combination with cut) will be flexible enough to handle this. And it seems as though what you really want is keys in file1 that are not in file2 and vice versa - not strictly a line-by-line diff. If the input files are big, I would go with perl, but for small files this awk script works for the input provided: %cat a.awk BEGIN ...


3

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 the lines in file2 for which column 2 has ...


0

Assuming those are all *.jpg files, do a: To find the Files present: grep -Ff <(for i in </path/to/directory/a>/*.jpg ; do md5sum $i | awk {'print $1'}; done) <(find </path/to/directoryb/ -iname "*.jpg" | xargs md5sum) The for loop here creates a list of md5 checksums of all the *.jpg files in directory 'a' and the find here will create a ...


0

See the answer for a similar question from two weeks ago. find . -type f -exec md5sum {} + | sort | sed 's/ */!/1' | awk -F\| 'BEGIN{first=1}{if($1==lastid){if(first){first=0;print lastid, lastfile}print$1, $2} else first=1; lastid=$1;lastfile=$2}'


1

Since you want to compare them by content, using hashes seems to be a way to do it. You can use the find command to get a list of file paths of a directory. The -type f option will leave out all directories and only output paths to regular files. The -exec md5sum {} \; option will take the found paths and gives them to the md5sum command to turn into a list ...


0

If you don't to modify files, just print differences, then one option is to simple ignore all white spaces with -w option, so that you can use your braces normally diff -wy file-{a,b} | less Of course this method only works if there are no other important changes in whitespace. If your intention is to repair the files then I would recommend to use ...


0

with grep and without sorting files: $ (cat file2; grep -vf file2 file1) > output ----- or ----- $ grep -vf file2 file1) >> file2 # append to end of file2 With comm and sort: $ (comm -12 <(sort file1) <(sort file2); comm -3 <(sort file1) <(sort file2) ) > output comm -12 file1 file2 Print only lines present in ...


1

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 │   ├── file1 │   └── file2 └── dirB └── ...


0

Watch this video which will explain everything you want.



Top 50 recent answers are included