3 ms·
Grep treats the pattern as a newline-separated list of items to search for. From https://www.gnu.org/software/grep/manual/grep.html#Introduction https://www.gn
by uraza 8y ago
Grep treats the pattern as a newline-separated list of items to search for.
From https://www.gnu.org/software/grep/manual/grep.html#Introduction https://www.gnu.org/software/grep/manual/grep.html#Introduct...: "Since newline is also a separator for the list of patterns, there is no way to match newline characters in a text."
- indigodaddy 8y agoRight, and actually, it looks like only 'ls | grep "${data}" ' (eg, the data var double-quoted) works: [jbrown@tools1 testdir1]$ data='testfile1 > testfile2 > testfile3 > testfile4 > testfile5 > testfile6 > testfile7 > testfile8 > testfile9 > testfile10' [jbrown@tools1 testdir1]$ echo $data testfile1 testfile2 testfile3 testfile4 testfile5 testfile6 testfile7 testfile8 testfile9 testfile10 [jbrown@tools1 testdir1]$ ls | grep `echo ${data}` <<NO OUTPUT>> [jbrown@tools1 testdir1]$ ls | grep ${data} <<NO OUTPUT>> [jbrown@tools1 testdir1]$ ls | grep "${data}" testfile1 testfile10 testfile2 testfile3 testfile4 testfile5 testfile6 testfile7 testfile8 testfile9 Believe that using echo in the backticks may amount to same effect as 'ls | `cat ..filelist.txt` (eg, results in ENOENT) And of course, as many have mentioned grep -f does what I was looking for and would have prevented this whole exercise: [jbrown@tools1 testdir1]$ ls | grep -f ../filelist.txt testfile1 testfile10 testfile2 testfile3 testfile4 testfile5 testfile6 testfile7 testfile8 testfile9
- kwoff 8y agoFor multi-line greps (rare, I guess), I use: pcregrep -Mr