Help me to sort text files

February 27, 2011 at 13:00:05
Specs: Windows XP
I'm trying to get a batch or vb-script (or an other script that works) which can alphabetically sort the content of text files in a folder.

The sorted content should be a replacement of the content of the original file (no new files) and it should work for every file in that folder. Maybe stupid but the script shouldn't sort itself, so it should make referral to the folder with the files.

Note that the files are txt, but have a numerical extension, which can be between .000 and .999

Example:
example.123 has a content of:
3
9
1
11
56
999

The result of the batch of vbscript (or something else simple) should be
example.123 with the content:
1
11
3
56
9
999

Hopefully somebody can help! Sorry for my English


See More: Help me to sort text files

Report •

#1
February 27, 2011 at 13:30:46
I hope I understood your a bit confused request. Be aware the script is not tested.

@echo off & setlocal EnableDelayedExpansion
pushd My_Folder
for /L %%j in (0 1 999) do (
  set cnt=00%%j
  set cnt=!cnt:~-3!
  for %%z in (*.!cnt!) do (
    sort < "%%z" > "%%~nz.tmp"
    del "%%z"
    ren "%%~nz.tmp" "%%z"
  )
)
popd


Report •

#2
February 27, 2011 at 18:36:06
http://www.computing.net/answers/pr...


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
February 28, 2011 at 02:41:14

"Note that the files are txt, but have a numerical extension, which can be between .000 and .999."

Not exactly the same question reported in the pointed post.

And NO a batch script can't overwrite an existing file, it has to sequentially read it and rewrite to a new one.


Report •
Related Solutions


Ask Question