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 $pattern
would rungrep $pattern file1 file2 ...
, and look at the contents of the files – ilkkachu Aug 28 '21 at 19:22ls
. 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
– Nasir Riley Aug 28 '21 at 19:27\d
on the command as regex. Does it look inside file and filenames ? – CodeWeed Aug 28 '21 at 22:37