Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep does not take pattern from file

Tags:

linux

grep

I have a pattern file, say t.txt, containing the following:

vali

and the file I want to run grep against, say a, containing the following:

validate
validate:

bw_validate:
 [echo] Validating project: CrossService_v1_59_5_1
 [echo] Found 62 errors and 28 warnings
 [echo] -----------------------------------------------------------------
 [echo] Validating project: CRM-UDB_59_4_2
 [echo] Found 25 errors and 28 warnings
 [echo] -----------------------------------------------------------------
 [echo] Validation Failed: At least one project contains errors.

notify:

BUILD FAILED
bw.xml:311: Validation Failed: At least one project contains errors.

if I execute:

grep -iE vali a

I get the expected output, i.e.:

validate
validate:
bw_validate:
 [echo] Validating project: CrossService_v1_59_5_1
 [echo] Validating project: CRM-UDB_59_4_2
 [echo] Validation Failed: At least one project contains errors.
bw.xml:311: Validation Failed: At least one project contains errors.

but if I execute:

grep -iE -f t.txt a

I don't get any match. files are readable and both in the same directory (from which I execute the command). I tried both with -f and --file=t.txt, --file='t.txt', --file="t.txt"

I'm on linux Fedora 16 64bit. Strangely enough, the same command works properly in windows with the grep/egrep porting.

Am I missing something? Any help is appreciated as this is giving me an headache :( thanks!

like image 679
Daniele Avatar asked Dec 28 '22 07:12

Daniele


1 Answers

It should work right (it works for me). The -f switch is specified by POSIX.

The fact that you say it's working on Windows gave me an idea: Could it be the t.txt file ends with a DOS newline? I tried it with a clean file (no newline), and it worked. Then I tried it with a DOS file, and I was able to reproduce your results.

Try dos2unix to "fix" DOS files.

like image 68
cnicutar Avatar answered Jan 09 '23 04:01

cnicutar