-
Notifications
You must be signed in to change notification settings - Fork 1
sh Parse Files And Run Commands On Them
Jason Lewis edited this page Jul 20, 2023
·
1 revision
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 {};"