I have a directory with lots of json and pdf files that are named in a pattern. I am trying to filter the files on name with the following pattern \d{11}-\d\.(?:json|pdf) in the command. For some reason it is not working. I believe it is due the fact that the xargs take the arguments one big line of string or when the input is split there is some whitespace, \n or null character.
ls | xargs -d '\n' -n 1 grep '\d{11}-\d\.(?:json|pdf)'
if I try just this ls | xargs -d '\n' -n 1 grep '\d' It selects file names with digits in them, as soon as I specify the multiplicity regex, nothing matches.
... |xargs grep $patternwould rungrep $pattern file1 file2 ..., and look at the contents of the filesls. You haven't clarified what the objective is, but if you are starting with wanting to find files that match a certain pattern(s), you are better off using something along the lines offind /path/to/directory -type f -name *:json -o -name *pdf