Masoud Abasian Masoud Abasian - 3 months ago 26
Bash Question

Find all matched pattern with grep

In txt1

S01A1P2
S01A1P5
S01A1P4


In txt2

data/train/wave/S01A1P3.mfc
data/train/wave/S01A1P7.mfc
data/train/wave/S01A1P8.mfc
data/train/wave/S01A1P1.mfc
data/train/wave/S01A1P5.mfc
data/train/wave/S01A1P6.mfc
data/train/wave/S01A1P2.mfc
data/train/wave/S01A1P4.mfc


Use
grep -f txt1 txt2
and result

data/train/wave/S01A1P4.mfc


But I want this result that find all pattern

data/train/wave/S01A1P5.mfc
data/train/wave/S01A1P2.mfc
data/train/wave/S01A1P4.mfc


What can I do?

Answer

txt1 contains CRLF line terminators. Try this:

grep -f <(dos2unix <txt1) txt2
Comments