Content-Length: 264793 | pFad | http://github.com/Genivia/ugrep/issues/462

32 File glob behavior of --sort=changed · Issue #462 · Genivia/ugrep · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File glob behavior of --sort=changed #462

Closed
gnozil opened this issue Jan 26, 2025 · 6 comments
Closed

File glob behavior of --sort=changed #462

gnozil opened this issue Jan 26, 2025 · 6 comments
Labels
works as documented Works (with a minor adjustment) as stated in the documentation

Comments

@gnozil
Copy link

gnozil commented Jan 26, 2025

If multiple files contain the pattern, I expected the results were sorted by chronological order, e.g., the log files normally were rotated by time, but ugrep results with --sort=changed seems not honor the flag or I mis-used the flag?

$ ug --sort=changed -m1 base dnf.log*
dnf.log
    19:	2025-01-25T12:13:56-0800 DEBUG repo: using cache for: base

dnf.log.1
    10:	2025-01-18T11:13:55-0800 DDEBUG Adding group file from repository: base

dnf.log.2
    29:	2025-01-11T10:13:19-0800 DEBUG repo: using cache for: base

dnf.log.3
    16:	2025-01-04T06:17:34-0800 DEBUG base: has expired and will be refreshed.

dnf.log.4
    25:	2024-12-28T04:13:14-0800 DEBUG repo: using cache for: base

Above results were from 7.2.0 version:

$ ug --version
ugrep 7.2.0 x86_64-pc-linux-gnu +avx512; -z:zlib,bzip2,lzma,zstd,7z,tar/pax/cpio/zip
License: BSD-3-Clause; ugrep user manual: <https://ugrep.com>
Written by Robert van Engelen and others: <https://github.com/Genivia/ugrep>
Ugrep utilizes the RE/flex regex library: <https://github.com/Genivia/RE-flex>

The file stat data:

$ stat dnf.log* | grep -E "File|Modify" | paste -d' ' - -
  File: dnf.log Modify: 2025-01-25 19:13:20.961446467 -0800
  File: dnf.log.1 Modify: 2025-01-25 12:13:53.189100491 -0800
  File: dnf.log.2 Modify: 2025-01-18 11:13:55.361105284 -0800
  File: dnf.log.3 Modify: 2025-01-11 09:47:45.542128044 -0800
  File: dnf.log.4 Modify: 2025-01-04 06:13:45.392720678 -0800

and I need to do with the tricky part $(ls -rt ...) in command line for expected results:

$ grep -m1 base $(ls -rt dnf.log*)
dnf.log.4:2024-12-28T04:13:14-0800 DEBUG repo: using cache for: base
dnf.log.3:2025-01-04T06:17:34-0800 DEBUG base: has expired and will be refreshed.
dnf.log.2:2025-01-11T10:13:19-0800 DEBUG repo: using cache for: base
dnf.log.1:2025-01-18T11:13:55-0800 DDEBUG Adding group file from repository: base
dnf.log:2025-01-25T12:13:56-0800 DEBUG repo: using cache for: base

This may be not a ugrep bug but I mis-used it, please correct me, thanks.

@gnozil gnozil changed the title Behavior of --sort=changed File glob behavior of --sort=changed Jan 26, 2025
@genivia-inc
Copy link
Member

genivia-inc commented Jan 26, 2025

What OS and version is this on? I don't see any problems on MacOS and Debian with --sort=changed or --sort=rchanged to reverse the order.

Perhaps you want to use --sort=rchanged? Because it looks like that is what you want. The changed order is from oldest to newest.

@genivia-inc
Copy link
Member

Note that the --sort=changed order is from oldest to newest file. The oldest has the smallest timestamp, hence it sorts from small (old) to large (new) time stamps. Whereas ls -t sorts from large (new) to small (old) timestamps. I'd rather like to keep the way ugrep sorts with the newest files appearing last with --sort=changed. Just use --sort=rchanged to reverse the order.

@genivia-inc genivia-inc added the works as documented Works (with a minor adjustment) as stated in the documentation label Jan 26, 2025
@gnozil
Copy link
Author

gnozil commented Jan 27, 2025

I am on Linux

$ head -n3 /etc/os-release 
NAME="Rocky Linux"
VERSION="9.4 (Blue Onyx)"
ID="rocky"

I have verified both changed and rchanged before previous issue reporting. Please see below examples, if I specify file name pattern, the both flags seem not working.

$ ug --sort=rchanged -m1 base dnf.log*
dnf.log
    19:	2025-01-25T12:13:56-0800 DEBUG repo: using cache for: base

dnf.log.1
    10:	2025-01-18T11:13:55-0800 DDEBUG Adding group file from repository: base

dnf.log.2
    29:	2025-01-11T10:13:19-0800 DEBUG repo: using cache for: base

dnf.log.3
    16:	2025-01-04T06:17:34-0800 DEBUG base: has expired and will be refreshed.

dnf.log.4
    25:	2024-12-28T04:13:14-0800 DEBUG repo: using cache for: base

$ ls -rt dnf.log*
dnf.log.4  dnf.log.3  dnf.log.2  dnf.log.1  dnf.log

$ ug --sort=changed -m1 base $(ls -rt dnf.log*)
dnf.log.4
    25:	2024-12-28T04:13:14-0800 DEBUG repo: using cache for: base

dnf.log.3
    16:	2025-01-04T06:17:34-0800 DEBUG base: has expired and will be refreshed.

dnf.log.2
    29:	2025-01-11T10:13:19-0800 DEBUG repo: using cache for: base

dnf.log.1
    10:	2025-01-18T11:13:55-0800 DDEBUG Adding group file from repository: base

dnf.log
    19:	2025-01-25T12:13:56-0800 DEBUG repo: using cache for: base

@gnozil
Copy link
Author

gnozil commented Jan 27, 2025

Also on Ubuntu:

$ head -n3 /etc/os-release 
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"

The ls -rt1 list files on expected order:

$ ls -rt1 dpkg.status.*
dpkg.status.6.gz
dpkg.status.5.gz
dpkg.status.4.gz
dpkg.status.3.gz
dpkg.status.2.gz
dpkg.status.1.gz
dpkg.status.0

The ugrep did not

$ ug -z -m1 --sort=rchanged Package dpkg.status.*
dpkg.status.0
     1:	Package: 7zip

dpkg.status.1.gz
     1:	Package: 7zip

dpkg.status.2.gz
     1:	Package: 7zip

dpkg.status.3.gz
     1:	Package: 7zip

dpkg.status.4.gz
     1:	Package: 7zip

dpkg.status.5.gz
     1:	Package: 7zip

dpkg.status.6.gz
     1:	Package: 7zip

@gnozil
Copy link
Author

gnozil commented Jan 27, 2025

Okay, with further tries, it showed that if I specified directory rather than file name pattern, the sorting works for the files under the directory. I expected files to be sorted from older to newer, then --sort=changed is the right flag.

$ ug -zr -m1 --sort=changed Package /var/backups
/var/backups/apt.extended_states.6.gz
     1:	Package: iucode-tool

/var/backups/apt.extended_states.5.gz
     1:	Package: iucode-tool

/var/backups/apt.extended_states.4.gz
     1:	Package: iucode-tool

/var/backups/apt.extended_states.3.gz
     1:	Package: iucode-tool
...

@genivia-inc
Copy link
Member

genivia-inc commented Jan 27, 2025

Subdirectories are sorted separately, the ugrep man page says "Subdirectories are sorted and displayed after matching files.". Furthermore, files specified on the command line will NOT be sorted but rather presented in the order specified on the command line as the man page says. Therefore, sorting applies to recursive search with globs (options -g, -t, -O etc). The ordered result may not be identical to the order of ls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
works as documented Works (with a minor adjustment) as stated in the documentation
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Genivia/ugrep/issues/462

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy