M
M
Marinaserova2019-09-24 17:00:14
linux
Marinaserova, 2019-09-24 17:00:14

What is the command to enter for filtering in Linux?

Hello!
There are 2 files file A and file B
Contents of file A:

id1:441
id2:458
id3:456
id4:233

B file content:
id1
id2

What command should be done in the Linux terminal in order to display only the lines:
id1:441
id2:458

Answer the question

In order to leave comments, you need to log in

6 answer(s)
Q
q2zoff, 2019-09-24
@q27off

fgrep -f {B,A}.txt

A
Alexander, 2019-09-24
@zkelo

cat A.txt | egrep "^id\d:\d+"

R
Rosh1ck, 2019-09-24
@Rosh1ck

I'm not sure that I understood the problem correctly, but I'll make an assumption:

cat fileA | egrep "id1|id2"
id1:441
id2:458

P
pfemidi, 2019-09-24
@pfemidi

cat A.txt | grep -f B.txt

S
Saboteur, 2019-09-24
@saboteur_kiev

while read;do grep $REPLY A;done<B

3
3vi1_0n3, 2019-09-25
@3vi1_0n3

join --nocheck-order -t : ./B ./A

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question