问题
So I have this code:
find cobacoba -type f | xargs -n 5 bash -c 'a=(${0} ${1} ${2} ${3} ${4}); echo "File #: ${a[*]}";'
Hoping Result:
File #: cobacoba/1.3 cobacoba/1.6 cobacoba/1.q cobacoba/1.5
File #: cobacoba/1.1 cobacoba/1.q2 cobacoba/1.q23 cobacoba/1.4
File #: cobacoba/1.2
I would like to replace # with counter, like 1, 2, 3, so on...
回答1:
You can postprocess your output with awk
to replace #
with the line number:
find cobacoba -type f |
xargs -n 5 bash -c 'a=(${0} ${1} ${2} ${3} ${4}); echo "File #: ${a[*]}";' |
awk '{gsub("#", NR, $0); print}'
My source for this method: Sed replace pattern with line number
PS: one might argue I should have flagged the question as a duplicate instead of answering, but I think the context is sufficiently different to warrant an answer even if the solution is the same.
来源:https://stackoverflow.com/questions/57450254/need-counter-on-find-and-xarg-combo