Computing.Net > Forums > Programming > Dos Batch replace strings

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Dos Batch replace strings

Reply to Message Icon

Name: gnx
Date: April 14, 2009 at 15:33:33 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: April 14, 2009 at 20:10:27 Pacific
Reply:

use nawk on Solaris

# awk '/AuthAccept/&&/CN=/{sub(/.*CN=/,"");sub(/,.*/,"");print }' file
n071143

Unix Win32 tools | Gawk for Windows


0

Response Number 2
Name: gnx
Date: April 14, 2009 at 22:46:07 Pacific
Reply:

huh? this is for windows I wont change my OS just to do that lol


0

Response Number 3
Name: ghostdog
Date: April 15, 2009 at 00:02:37 Pacific
Reply:

my bad. i posted to the wrong thread.

Unix Win32 tools | Gawk for Windows


0

Response Number 4
Name: ghostdog
Date: April 15, 2009 at 00:12:18 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Dos Batch replace strings

nt batch to replace string in srt file www.computing.net/answers/programming/nt-batch-to-replace-string-in-srt-file/19260.html

Batch command string substitution www.computing.net/answers/programming/batch-command-string-substitution/18209.html

Replace String in .bat file www.computing.net/answers/programming/replace-string-in-bat-file/19152.html