[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sorting using two field separators
From: |
Tapani Tarvainen |
Subject: |
Re: Sorting using two field separators |
Date: |
Mon, 18 Oct 2021 17:38:05 +0300 |
On Sun, Oct 17, 2021 at 06:00:19PM +0000, tolugboji (tolugboji@protonmail.com)
wrote:
> "find" uses a null character. Could one make the awk command know that?
>
> find "$fdir" -type f -name "${fnam}-*.png" -print0 |
> awk -F'[-.]' '{print $(NF-1), $0}' |
> sort -znk 1,1 | cut -d ' ' -f2-
> echo
While awk can handle NULs, this being a bash group I'd like to suggest
an alternative:
mapfile -d '' -t < <(find . -name '*.png' -print0 | sort -zt- -k2n)
for f in "${MAPFILE[@]}" ; do
echo "$f" # do whatever with "$f"
done
Note, the sort may not work as desired if there are dashes in
directory names in find output.
If the files are in the current directory that's not a problem, but
then you don't need find at all:
mapfile -d '' < <(printf "%s\0" *.png | sort -zt- -k2n)
--
Tapani Tarvainen
- Sorting using two field separators, (continued)
- Sorting using two field separators, tolugboji, 2021/10/17
- Re: Sorting using two field separators, Alex fxmbsw7 Ratchev, 2021/10/17
- Sorting using two field separators, tolugboji, 2021/10/17
- Re: Sorting using two field separators, Alex fxmbsw7 Ratchev, 2021/10/17
- Sorting using two field separators, tolugboji, 2021/10/17
- Re: Sorting using two field separators, Dennis Williamson, 2021/10/17
- Sorting using two field separators, tolugboji, 2021/10/17
- Sorting using two field separators, tolugboji, 2021/10/17
- Sorting using two field separators, tolugboji, 2021/10/17
- Re: Sorting using two field separators, Alex fxmbsw7 Ratchev, 2021/10/18
- Re: Sorting using two field separators,
Tapani Tarvainen <=