How do i find out lines of a file that are not present in another file?

Solution 1:

Simply

grep -vxf A B

If you want the line number of the non-matching lines also:

grep -nvxf A B

If B has multiple non-matching identical lines, and you only want to print out the identical lines once, then

grep -vxf A B | sort | uniq  

Solution 2:

you can sdiff command. Usage: sdiff file1.txt file2.txt

you can have the lines any where.

What are the uncommon lines are there they will be indicated with > symbol. Look at the below image. Example:

enter image description here

Solution 3:

You say lines can be at any position, but if position is not important to you (just want to know the differences), use comm:

   Compare sorted files FILE1 and FILE2 line by line.

   With  no  options,  produce  three-column  output.  Column one contains
   lines unique to FILE1, column two contains lines unique to  FILE2,  and
   column three contains lines common to both files.

It requires files to be sorted, luckily sort can help with that. You can sort A > A.sorted to sort it, do something similar with B, and then:

comm -1 -3 A.sorted B.sorted

this will print "lines unique to FILE2" which in this case is B.sorted.

You can also do the sort inline, the command is a bit more cumbersome to type but you'd save a few steps:

comm -1 -3 <(sort A) <(sort B)