Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Match Highest number in directory

20 views
Skip to first unread message

T

unread,
May 30, 2012, 1:52:32 PM5/30/12
to
Hi,

I have a directory with the following files:

1
2
2.save
3

I would like to simply find the highest number file in the directory.
I do this with bash like so:

for dir in `ls . | grep -e '^[0-9]*$'`
do
if [ $dir -gt $x ]; then
x=$dir
fi
done

Unfortunately it doesn't appear that the glob function in TCL
understands the anchor or beginning of line function. How does one do
this in TCL?

Thanks for any help in advance.
Tom

Robert Heller

unread,
May 30, 2012, 2:42:00 PM5/30/12
to
set x 0
# glob replaces ls
foreach dir [glob -nocomplain *] {
# Regexp replaces grep. Note: feel free to combine the tests into a
# single if. I used two if statements merely to clarify line-by-line
# functionallity.
if {[regexp {^[0-9]*$} $dir] > 0} {
if {$dir > $x} {set x $dir}
}
}


--
Robert Heller -- 978-544-6933 / hel...@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments



Arjen Markus

unread,
May 31, 2012, 10:13:54 AM5/31/12
to
Op woensdag 30 mei 2012 20:42:00 UTC+2 schreef Robert Heller het volgende:
Or:

foreach file [glob {[0-9]*}] {
...
}

glob uses glob patterns and they do allow character classes, but
are more limited than regular expressions.

Regards,

Arjen
0 new messages