Dos Batch replace strings

April 14, 2009 at 15:33:33
Specs: Windows XP
Hey,,

So far I have this:
@ECHO OFF
setLocal EnableDelayedExpansion

set str=abcdefghijklmnopqrstuvwxyz
set /a a=0
set /a max=25
:reset
set ran=%random%
set /a ran-=1
if %ran% gtr %max% goto reset
if %ran% lss 1 goto reset
set st=!str:~%ran%,3!
echo %st%

set cnt=
set ran=

it gets a set of 3 random characters from "str" well, kinda random^^

I have a file "media.txt" in this format:
[Filename.mp3]
[Filename.mp3]

and so on.. what I want to do is replace everything between [] with the random characters i generated.

thx for any help,
gnx.


See More: Dos Batch replace strings

Report •


#1
April 14, 2009 at 20:10:27
use nawk on Solaris
# awk '/AuthAccept/&&/CN=/{sub(/.*CN=/,"");sub(/,.*/,"");print }' file
n071143

Unix Win32 tools | Gawk for Windows


Report •

#2
April 14, 2009 at 22:46:07
huh? this is for windows I wont change my OS just to do that lol

Report •

#3
April 15, 2009 at 00:02:37
my bad. i posted to the wrong thread.

Unix Win32 tools | Gawk for Windows


Report •

Related Solutions

#4
April 15, 2009 at 00:12:18
if you can use Python for Windows
import  string
import random
random_letters = ''.join(random.sample(string.letters,3))
for line in open("file"):
    line = line.strip()
    if "[" in line:
        print "[" +random_letters + "." +line[1:].split(".")[-1] 


ouput:
[code]
c:\test> python test.py
[VsZ.mp3]
[VsZ.mp3]

[/code]

Unix Win32 tools | Gawk for Windows


Report •


Ask Question