How can I find lines in one file but not the other using bash scripting?

If it's ok to use a temp file, try this: grep include file1. H > tmp && grep -f tmp -v file2. H | grep include This extracts all includes from file1.

H and writes them to the file "tmp uses this file to get all lines from file2. H that are not contained in this list extracts all includes from the remainder of file2. H It probably doesn't handle differences in whitespace correctly etc, though EDIT: to prevent false positives, use a different pattern for the last grep (thanks to jw013 for mentioning this): grep include file1.

H > tmp && grep -f tmp -v file2. H | grep "^#include.

If it's ok to use a temp file, try this: grep include file1. H > tmp && grep -f tmp -v file2. H | grep include This extracts all includes from file1.

H and writes them to the file "tmp" uses this file to get all lines from file2. H that are not contained in this list extracts all includes from the remainder of file2. H It probably doesn't handle differences in whitespace correctly etc, though.

EDIT: to prevent false positives, use a different pattern for the last grep (thanks to jw013 for mentioning this): grep include file1. H > tmp && grep -f tmp -v file2. H | grep "^#include.

1 Maybe change that last grep pattern to '^#include' unless you also want to see random lines of code where you happened to use the word "include" – jw013 Aug 4 at 7:53 @jw013: I'ved added it, thanks. – Frank Schmitt Aug 4 at 8:03.

This is a one-liner, but does not preserve the order: comm -13.

1 because I didn't know about comm before :-) – Frank Schmitt Aug 4 at 7:33.

This variant requires an fgrep with the -f option. GNU grep (i.e. Any Linux system, and then some) should work fine.

# Find occurrences of '#include' in file1. H fgrep '#include' file1. H | # Remove any identical lines from file2.

H fgrep -vxf - file2. H | # Result is all lines not present in file1.h. Out of those, extract #includes fgrep '#include' This does not require any sorting, nor any explicit temporary files.In theory, fgrep -f could use a temporary file behind the scenes, but I believe GNU fgrep doesn't.

POSIX specifies -f so any POSIX compliant grep should have it. – jw013 Aug 4 at 8:07 +1 for not needing temp files / sorting – jw013 Aug 4 at 8:57.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send