|
Answer» Hey all, I'm trying to do something very specific here... I have a file, it's anywhere from 1 to 15 lines, and each line only contains one word (a computer name). This "list" needs to be fed back into another text file, newlist.txt, in the format below:
word1, word2, word3, word4, etc...
So basically, I want to make it comma delimited. I've tried various THINGS with FOR and IF, but they're just not working; best I got was this:
word1 , word2 , word3 , etc...
Any help WOULD be appreciated, but if it could be limited to dos COMMANDS, that would be preferable. I'm not sure I'll be in an ENVIRONMENT where VB scripts will work, but if that's my *only* way, so be it.
Thanks!You didn't MENTION an OS but this has been known to work on some of them:
Code: [Select]echo off setlocal enabledelayedexpansion for /f %%v in (myFile.txt) do ( call set oneline=!oneline!,%%v ) set oneline=!oneline:~1! echo %oneline%
Be sure to change myFile.txt to something more usable.
this works on dos/xp Code: [Select]@echo off set text= for /f %%a in (myFile.txt) do call :settext %%a goto end :settext if "%text%"=="" ( set text=%1 ) else ( set text=%text%, %1 ) goto :eof :end echo %text% >newlist.txt Quote from: Ceeler on March 28, 2008, 02:19:21 PM I'm not sure I'll be in an environment where VB scripts will work, but if that's my *only* way, so be it.
unless you are working with prehistoric machines with prehistoric OS, otherwise, yes vbscript can be used, from Win95/98 onwards. Here's one Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "c:\test\file.txt" s="" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfLine s=objFile.ReadLine & "," & s Loop WScript.Echo s save as script.vbs and on command line(batch) Code: [Select]c:\test> cscript /nologo script.vbs
|