sh Parse Files And Run Commands On Them - gecko-8/devwiki GitHub Wiki

Up

find "<documents path>" -type f -name "<file pattern with wildcards>" -print0 | \
  # Get the relative path to the input file
  xargs -0 -n1 | \
  # extract just the basename
  grep -Po "(?<=<document path>/).*(?=<document extension>)" | \
  # xargs runs sh command(s) on each filename
  xargs -I {} sh -c "<semi colon separated commands using {} for the filename>"

Example:

find "./docs" -type f -name "*.txt" -print0 | \
  # Get the relative path to the input file
  xargs -0 -n1 | \
  # extract just the basename
  grep -Po "(?<=.docs/).*(?=.txt)" | \
  # xargs runs sh command(s) on each filename
  xargs -I {} sh -c "echo {}; echo {};"