by indigodaddy · 8y ago · 0 comments
I guess essentially what I was doing was really the same as the following (excepting the echo derp):
[jbrown@tools1 testdir1]$ ls |
grep 'testfile1
> testfile2
> testfile3
> testfile4
> testfile5
> testfile6
> testfile7
> testfile8
> testfile9
> testfile10'
testfile1
testfile10
testfile2
testfile3
testfile4
testfile5
testfile6
testfile7
testfile8
testfile9
...the above has the same/desired output (including the missing testfile1 that the echo derp had missed).I guess though that I still don't fully understand how/why grep is able to interpret/execute each newline individually, eg kind of cycling through it.
EDIT - I do realize dozzie pretty much explained it, and what's happening here, however still sort of bewildered that grep is able to perform the operation sort of separately on each newline as an individual argument, and sort of parse through each one...
From 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."
[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