For performance reasons, I want to use find to list a large number of files, but also include a counter on each line. The following is what I have so far:
local root_dir="."
local ouptut_file="/tmp/foo.txt"
File_Number=99 ## Initial value
echo "" > "${ouptut_file}" ## Initialize file to empty
find "$root_dir" \
-type f \
-depth 2 \
-name '*.xxx' \
-print0 \
| sort -z \
| xargs -0 printf "DoSomething %5d '%s'\n" $[File_Number++] -- \
> "${ouptut_file}"
This outputs
DoSomething 99 '--'
DoSomething 0 'dirA/dirB/file1.xxx'
DoSomething 0 'dirA/dirB/file2.xxx'
DoSomething 0 'dirA/dirB/file3.xxx'
what I want is
DoSomething 100 'dirA/dirB/file1.xxx'
DoSomething 101 'dirA/dirB/file2.xxx'
DoSomething 102 'dirA/dirB/file3.xxx'
How do I include the counter and also eliminate the first spurious line in the output.
System: Am using bash on macOS Ventura 13.0.1