Find lowest number (txt) and show row

June 14, 2009 at 02:23:12
Specs: Windows 7
There is a limit in the subject,
so what I need is a script that finds the 5 lowest numbers in a text file, wich contains aomething like this:

23 Richard 2009-06-01
5 Lowe 2009-06-02
8 Max 2009-06-03
31 Anna 2009-06-03
7 Tom 2009-06-04
14 Alex 2009-06-06
54 Greg 2009-06-06
18 Patrick 2009-06-07
13 Andreas 2009-06-08

I need to get the five lowest numbers in the beginning of the row.
There is a possibility to remove a date
this is meant for a counter script.

Please help guys!

Thanks in advice!

and so on...


See More: Find lowest number (txt) and show row

Report •


#1
June 14, 2009 at 03:36:10
You could use SORT. BUT you need to pad with leading zeros.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
June 14, 2009 at 03:40:55
:: GETLOW.BAT Usage: getlow [drive:][path]filename
@echo off & setlocal EnableDelayedExpansion
type nul > %~n0.tmp
for /F "tokens=1*" %%j in ('type %*') do (
  set tag=%%j
  if %%j lss   10 set tag=0!tag!
  if %%j lss  100 set tag=0!tag!
  if %%j lss 1000 set tag=0!tag!
  echo.!tag! %%j %%k>> %~n0.tmp
)
type nul > lowest.txt
set cnt=5
for /F "tokens=1*" %%j in ('sort ^< %~n0.tmp') do (
  echo.%%k>> lowest.txt
  set /A cnt-=1
  if !cnt! equ 0 goto :DONE
)
:DONE
type lowest.txt
del %~n0.tmp
:: End_Of_Batch


Report •

#3
June 14, 2009 at 04:21:30
windows sort.exe doesn't cut it at all. if you can, download GNU coreutils from here , and use the sort and head command to get your results
C:\test>sort.exe file.txt -n | head -5
5 Lowe 2009-06-02
7 Tom 2009-06-04
8 Max 2009-06-03
13 Andreas 2009-06-08
14 Alex 2009-06-06


the -n option gives you numeric sort.

Report •

Related Solutions

#4
June 14, 2009 at 04:32:38
Hi IVO,

Nice one. I was too lazy to do the padding.


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question