Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How can I sort a directory listing in VMS by date like the ls -t command does in Unix.
Thanks.
Jim Laragy

try to create an output file with:
dir/dat/width=(filename=30)/col=1/out=out.lis
and then sort by the following command (you have to count the positions of the date information and maybe you want to sort by the year first, then month and day)
$ SORT/KEY=(POS:16,SIZ:3)/KEY(POS:1,SIZ:11) -
_$ /KEY=(POS:40,SIZ:2,DESC) out.lis out_sort.LIS
This SORT command identifies three key fields. The input file, out, is first sorted by the key beginning in position 16, then by the key beginning in position 1, and finally by the key beginning in position 40. The third key used sorts in descending order.
As you can sea, there is no simple way just using a command, but it works.Hope this helps
Klaus

There are two issues here. One is trying to get rid of the pesky temporary file, the other is to sort a date field containing the month names. The latter can be done with a SORT specification file. Here is an example which assumes /WIDTH=(FILENAME:40). Adjust the POSITION values for different widths:
We'll call it DIRDATE.SPEC and assume it's in SYS$LOGIN./FIELD=(NAME:YEAR, POSITION:50, SIZE:4, CHAR)
/FIELD=(NAME:MONTH, POSITION:47, SIZE:2, CHAR)
/FIELD=(NAME:DAY, POSITION:43, SIZE:2, CHAR)
/FIELD=(NAME:TIME, POSITION=55, SIZE:11,CHAR)
/FIELD=(NAME:RECORD, POSITION:1, SIZE:80, CHAR)
/KEY=YEAR
/KEY=MONTH
/KEY=DAY
/KEY=TIME
/DATA=RECORD
/COLLATING_SEQUENCE=(SEQUENCE=("AN","EB","AR","PR","AY","UN",
"UL","UG","EP","CT","OV","EC","0"-"9"),
MODIFICATION=("'"="19"),FOLD)-- end of DIRDATE.SPEC
Now the problem of the temporary file. Since V7.1, OpenVMS has had a pipe command, a bit like Unix (but not quite as slick). So, we can now do the whole thing in one command:
$ PIPE DIRECTORY/DATE -
/WIDTH=(FILENAME:40)/COLUMN=1 | -
SORT/SPECIFICATION=SYS$LOGIN:DIRDATE.SPEC -
SYS$PIPE: SYS$OUTPUT:The result will be a directory sorted by date (except that the trailer line will end up at the top of the listing).

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |