Right now I wanted to filter a file through (e)grep using a text file containing the patterns (regular expressions). When I tried each individual pattern directly on the commandline it worked flawlessly, but trying "grep -f pattern.txt bigfile.txt" returned nothing.

So I read the file line by line using a bash script, but when I echo'ed the read pattern things behaved weird.
[SOLUTION]
The pattern file was produced on a Windows computer, thus it was DOS encoded. Running it to "unix2dos" (or "fromdos") solved all my problems. I didn't suspect that problem at first, because usually vim would have displayed the blue ^M characters - but it didn't.
[BACKGROUND INFO]
Examples:
pattern.txt contained only 1 line (for testing):
Code: Select all
2007.10.25 12:(49|5[0-5])
Code: Select all
#!/bin/bash
LOG="mylog.log"
PATTERNS="patterns.txt"
cat $PATTERNS | while read line
do
echo $line
echo "left $line right"
done
...it cut the first digit off the pattern and shifted its position in the output string. Quite puzzling, but finally solved by "fromdos".2007.10.25 12:(49|5[0-5])
right007.10.25 12:(49|5[0-5])