I’m using the -l flag with grep to just print the matching file names.
I want to then list the results (files) in ascending order i.e. newest last.
Obviously
grep -l <pattern> *.txt | ls -rt
is not what I need, since the ls -lrt merely outputs all files.
Try:
We first use
lsto list*.txtfiles and sort them by modification time (newest last), then for each entry run them throughgrepso we only print out files that contain the pattern.