It's not 100% clear to me what you are doing, but let's start with two sorted BED files:
The operation that matches the wording of your question #1 has the following structure:
$ bedops --element-of -1 ChipA.bed ChipB.bed > AnswerQ1A.bed
AnswerQ1A.bed is made up of elements from
ChipA.bed that overlap elements in
ChipB.bed by one or more bases. This preserves columnar data in
Likewise, the following command gives different output:
$ bedops --element-of -1 ChipB.bed ChipA.bed > AnswerQ1B.bed
AnswerQ1B.bed is made up of elements from
ChipB.bed that overlap elements in
ChipA.bed by one or more bases. This, too, preserves columnar data in
What you might be interested is the set of overlapping elements common to both input sets:
$ bedops --element-of -1 ChipA.bed ChipB.bed > ChipAOverlappingB.bed
$ bedops --element-of -1 ChipB.bed ChipA.bed > ChipBOverlappingA.bed
$ bedops --everything ChipAOverlappingB.bed ChipBOverlappingA.bed > ChipAIfAndOnlyIfOverlappingB.bed
--element-of if you need more than the input sets' genomic regions, i.e. to preserve columnar data (IDs, scores, etc.). You might want to further filter your element sets by other criteria contained in these extra columns.
The following operation that matches your question #2 gives a different answer:
$ bedops --merge ChipA.bed ChipB.bed > AnswerQ2.bed
AnswerQ2.bed is made up of just genomic regions that are calculated from the genomic regions in both
ChipB.bed. This second answer does not preserve columnar data. The output will not tell you where the region originally came from (though simple set operations back on
ChipB.bed answer that question).
You might want this instead, if you are looking to discover genes in a set of genomic coordinates, and if the columnar data in
ChipB.bed is not important or relevant. This will depend on your experiment.
For instance, if you want to look at the merged regions only within +/- 20 kbase of a set of TSSs, then (assuming you have a sorted BED file containing TSSs) you could do the following:
$ bedops --merge --range 20000 TSSs.bed \
| bedops --element-of -1 AnswerQ2.bed - \
This last file is a constrained set of merged regions from
AnswerQ2.bed — you might only be interested in focusing downstream searches in this subset of regions.