Intersection between two files

Barry

I am a first-timer at programming, and I'm trying to find the intersection of two text files.

file1.txt
a a
a b
a a
a c

file2.txt
a a

I want to get the result below in file1 (lines in file2 that are in file1)

a a
a a

I try to use grep command in Linux but I don't know how to do it.

derlarsschneider

I saw something similar here https://stackoverflow.com/a/36591385/4053813

< file1 xargs -I % grep -xF '%' file2

Edit: As pointed out by @Julien Lopez I added -xF options to grep command.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding intersection between two text files in windows cmd

From Dev

Intersection between two shell lists without temp files

From Dev

Intersection of two json files

From Dev

Intersection between multiple files

From Dev

intersection between 2 files

From Dev

Intersection between two arrays

From Dev

Find intersection of lines in two files

From Dev

Array intersection of two large files

From Dev

Showing the intersection between two strings

From Dev

Finding the Intersection between two Vectors

From Dev

intersection between two maps in clojure

From Dev

Intersection between two geographic lines

From Dev

Finding the Intersection between two Vectors

From Dev

Testing for intersection between two arcs

From Dev

Python - Getting the intersection of two Json-Files

From Dev

intersection of two files according to the first column

From Dev

Intersection between two list of strings python

From Dev

Find intersection between two data sets

From Dev

Find the intersection between two geographical data points

From Dev

Draw Intersection between two point clouds in OpenGL

From Dev

Intersection-over-union between two detections

From Dev

get intersection between two ranges in javascript

From Dev

Find the intersection between using two array

From Dev

Drawing line between intersection of two shapes

From Dev

Find the intersection between two geographical data points

From Dev

Find and mark the intersection between two lines

From Dev

Element intersection between two matrices in R

From Dev

Algorithm to check intersection between two objects

From Dev

find point of intersection between two arc