Skip to main content

Timeline for Xargs into second side of pipe?

Current License: CC BY-SA 3.0

19 events
when toggle format what by license comment
Apr 23, 2017 at 7:44 comment added Stéphane Chazelas @Rakesh, d'oh missed that. See edit.
Apr 23, 2017 at 7:44 history edited Stéphane Chazelas CC BY-SA 3.0
added 1516 characters in body
Apr 22, 2017 at 20:37 comment added user218374 @StéphaneChazelas But the OP's first line says that & i quote: I'm expecting each line from file1 to be the value for grep at the end of the third pipe. So I was taking my cue from there.
Apr 22, 2017 at 20:33 comment added Stéphane Chazelas @Rakesh, or xargs -d '\n' if you're going to use GNUisms. But the assumption was that the quote handling was potentially desired here. After all, that's what xargs is for: parse lists of words.
Apr 22, 2017 at 19:41 comment added user218374 @PhilipKirkbride No extra spaces/quotes/metachars wouldn't break it if you use the -0 option: < file1.txt tr '\n' '\0' | xargs -0 -I{} grep -e {} file2.txt
Apr 22, 2017 at 16:36 comment added Stéphane Chazelas @Philip, see edit for more alternatives.
Apr 22, 2017 at 16:36 history edited Stéphane Chazelas CC BY-SA 3.0
added 591 characters in body
Apr 22, 2017 at 16:24 vote accept Philip Kirkbride
Apr 22, 2017 at 16:24 comment added Philip Kirkbride After removing the extra spaces at the end of each line all your suggested answers worked. But yes for any future readers, extra space will break this.
Apr 22, 2017 at 16:21 comment added Stéphane Chazelas @Philip, I suspect if you replace sh -xc with bash -xc, you'd see grep -e 'apples ', that is that there are spaces at the end of the lines of file1.txt which sh (presumably dash as that looks like Ubuntu) doesn't show with xtrace.
Apr 22, 2017 at 16:15 comment added Philip Kirkbride results: imgur.com/a/kuwBW
Apr 22, 2017 at 16:14 comment added Stéphane Chazelas @PhilipKirkbride, what do you see if you replace sh -c with sh -xc?
Apr 22, 2017 at 16:11 comment added Philip Kirkbride It doesn't return anything imgur.com/a/CV56w
Apr 22, 2017 at 16:10 comment added Stéphane Chazelas @Philip, in which way does it not work for you?
Apr 22, 2017 at 16:09 comment added Philip Kirkbride I appreciate knowing the vulnerability but I don't understand why the vulnerable command works but none of the other ones suggested do.
Apr 22, 2017 at 16:07 comment added Stéphane Chazelas @Philip, see edit.
Apr 22, 2017 at 16:03 history edited Stéphane Chazelas CC BY-SA 3.0
added 276 characters in body
Apr 22, 2017 at 16:03 comment added Philip Kirkbride When I used your commands they didn't work for me but the following modification did: cat file1.txt | xargs -I{} sh -c 'cat file2.txt | grep {}'
Apr 22, 2017 at 16:00 history answered Stéphane Chazelas CC BY-SA 3.0