On 08/12/2022 23:52, Greg Wooledge wrote:
On Thu, Dec 08, 2022 at 09:53:37PM +0700, Max Nikulin wrote:I have tried slash (a character disallowed in file names) instead of space as field separator:The "problem" with that is we have slashes in our pathnames (%p) in almost all cases. But if we carefully build the read command, I think it should keep them intact.
I am trying to figure out if it is possible to avoid stripping of single (and only single) trailing slash. It is not an issue while "-type f" selector is used, but I am trying to evaluate if it may be used as a more general approach.
find dir dir/ dir// | sed -n l dir$ dir/$ dir//$ find dir dir/ dir// -printf '%T@/%TY-%Tm-%Td/%TT/%p\0' | sort -zn | while IFS=/ read -rd '' _ day time path; do printf '%s %s %s\n' "$day" "${time%.*}" "$path"; done | sed -n l 2022-12-09 22:13:14 dir$ 2022-12-09 22:13:14 dir$ 2022-12-09 22:13:14 dir//$Single trailing / disappeared. Using any other character may cause incorrect path in the output.