1.

Solve : New to DOS: SED replacement?

Answer»

Hi guys!!

Im a budding Unix programmer asked to make this simple tool in windows. Just wondering what i can do which is equivalent to unix here.

I have this line of text in a file

etokenadminpassword:: U2FsdGVkX18+EVZ2onfM3Er78ZCuEr94

I need to remove the FIRST word and the semicolon and have a file with just one line with

U2FsdGVkX18+EVZ2onfM3Er78ZCuEr94

in it. I would normally use 'sed' in Unix and pipe the output to another file. Does anyone have any DOS ideas here, because I cant FIND anything
assuming only that line in the file, here's a vbscript. save it as some name,eg myscript.vbs
Code: [Select]InputFileName="C:\temp\file.txt"
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oTS = FSO.OpenTextFile(InputFileName)
theString = oTS.ReadAll
oTS.Close
myArray = Split(theString," ")
WScript.Echo myArray(1)
output:
Code: [Select]C:\vbscript>cscript /nologo myscript.vbs
U2FsdGVkX18+EVZ2onfM3Er78ZCuEr94


or DOS batch
Code: [Select]echo off
For /F "tokens=1,2 delims= " %%a In (file.txt) Do (
echo %%b
)

However, since you know Unix, why not consider bringing Unix over to Windows , if you can afford it.
There's always cygwin, GNU sed,awk etc, even Services for Windows (SFU) Is there no way to do this without using what I assume is a Visual basic script. Could I not perhaps use Dos commands in a batch file similar to a shell script in Unix?

THanks though this is awesomeOh *censored* NEVER read the DOS part my badWorked like a charms thanks. I dont understand the

"tokens=1,2 delims= "                      part.

I mean i see your setting the delimiter as the space CHAR but what is token=1,2 for?

THanksAlso how can I tell if a txt file is empty or not
Thanks Quote from: shammer on June 08, 2007, 12:13:29 PM

Worked like a charms thanks. I dont understand the

"tokens=1,2 delims= "                      part.

I mean i see your setting the delimiter as the space char but what is token=1,2 for?
Yes, the space is the delimiter, and the 1,2 means only set tokens 1 and 2 (the first 2 tokens) so if there is more than one space, it will ignore the rest.

Quote from: shammer on June 08, 2007, 12:21:00 PM
Also how can I tell if a txt file is empty or not
Empty as in exists, but 0 bytes?
Code: [Select]for /f %%a in ('dir filename.txt /b') do if %%~za equ 0 echo %%a is %%~za bytes.You can get SED for Windows here

http://gnuwin32.sourceforge.net/packages/sed.htm

And there is a package of Unix utilits for Win32 here:
http://sourceforge.net/projects/unxutils/
You get all the goodies, like sed, grep, md5sum, wget, touch, head, tail, cut, and about 100 moreI use wget a lot.


Discussion

No Comment Found