Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xargs respect wildcards in searches

Tags:

bash

xargs

I have a file called file1.txt:

dir1
dir2
dir3
...

I wanted to use xargs to check if some files exist farther into the file system like this:

 cat file1.txt | xargs -i ls  /projects/analysis7/{}/meta_bwa/hg19a/*varFilter 2>/dev/null

But xargs never seems smart enough to expand the *. ie, it never finds the files even when they would match the pattern (if the * was expanded).

Any ideas?

like image 691
lonestar21 Avatar asked Dec 20 '22 20:12

lonestar21


1 Answers

You just need to add sh -c:

 cat file1.txt | xargs -i sh -c 'ls  /projects/analysis7/{}/meta_bwa/hg19a/*varFilter' 2>/dev/null
like image 179
Igor Chubin Avatar answered Dec 30 '22 07:12

Igor Chubin