Issue
I run a command, getFiles
, that outputs a newline delimited list filenames. Very similar to the output of ls -1
. The filenames all end in a number representing a kind of timestamp. Larger numbers are more recent. The filenames follow no pattern. e.g. file1234
, other44234
, something34142
, carrot123
.
I need to find the filename with the largest number (numerically). In this example other44234
.
After finding the filename I need to pass it as an argument into another command. i.e. doItToIt "$THE_FILE"
Solution
Another way:
$ sed -E 's/^([a-Z]+)([0-9]+)/\1 \2/' files.txt |
sort -n -k2 |
tail -n1 |
tr -d ' '
other44234
Answered By - Gilles Quenot Answer Checked By - Katrina (WPSolving Volunteer)