1.

Solve : how to change the comma to tab space in a text file by using batch command??

Answer»

how to make it?
as the export type must be csv FILE, i need to change it into tab delimited file.

thankshere's a vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strMyFile = "C:\test.txt"
Set objFile = objFS.OpenTextFile(strMyFile)
Do Until objFile.AtEndOfLine
WScript.Echo Replace(objFile.ReadLine,",", vbtab)
Loop
save as script.vbs and on command line
Code: [Select]c:\test> cscript /nologo script.vbs > newfile.csv
thanks! can i make it by .bat file?
yes you can. i will let somebody else show you. I don't want to waste my time with batch.thanks!Ghostdog gave you a better answer, at least the casual user can see what is happening.

The actual search and replace is simple, but getting that pesky tab character can be illusive. I ended up stealing one from an editor.

Code: [Select]setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (c:\a.csv) do (
set row=%%a
set row=!row:,= !
echo.!row!>>c:\c.tdf
)

Due to the magic of batch code, everything is not what it seems.

Quote from: ghostdog74 on April 23, 2008, 12:00:21 AM

yes you can. i will let somebody else show you. I don't want to waste my time with batch.

Then why are you wasting our time by posting in a thread where the question clearly asks "using batch commands?"
Quote from: Dias de verano on April 25, 2008, 01:26:01 PM
Quote from: ghostdog74 on April 23, 2008, 12:00:21 AM
yes you can. i will let somebody else show you. I don't want to waste my time with batch.

Then why are you wasting our time by posting in a thread where the question clearly asks "using batch commands?"

let me ask you, what do you understand by : "using batch commands" and "using pure batch commands" ? Quote from: ghostdog74 on April 25, 2008, 10:23:13 PM
let me ask you, what do you understand by : "using batch commands" and "using pure batch commands" ?

I understand both to mean "by means of batch files". The clue is the word "batch". The word "pure" appears to be your own insertion, the reason for which I can only guess at.
Quote from: Dias de verano on April 25, 2008, 11:35:46 PM
Quote from: ghostdog74 on April 25, 2008, 10:23:13 PM
let me ask you, what do you understand by : "using batch commands" and "using pure batch commands" ?

I understand both to mean "by means of batch files". The clue is the word "batch". The word "pure" appears to be your own insertion, the reason for which I can only guess at.

let me phrase it another way for you
Code: [Select]@echo off
cd /path
cscript /nologo script.vbs
exit
if you put the above into batch.bat, is this considered a batch file? Are those 4 lines batch commands?
I had taken OP's "make it into .bat" file to mean he wants to do it not the vbscript way, therefore I replied it can be done, which sidewinder has provided the batch version. I really do not have time to do up a batch solution back then. So i don't understand what's the fuss is with you. Yes they are, but you are using a crafty argument, by introducing the concept of "pure" batch commands. If one is allowed to call an external program, then of course one can whip up a piece of code in C, javascript, VBS, Visual Basic, QBasic, FreeBasic, or whatever. Then again, some "batch commands" are built into cmd.exe (or command.com) and some are separate compiled exe programs. Of these, some are installed by default and some are available as toolkits e.g. the various Microsoft Resource Kits, the GNU Core Utilities, and of course many people install such old friends as sed and awk.

I think a LOT depends on individual circumstances. While home users using a machine under their control and ownership can do what they please, many people using employer's or school/college computers are prevented from installing add-on programs or collections of programs. People writing scripts for deployment to many PCs may not be sure that all target machines will have the necessary programs installed and in the right places. Many such computers have Windows scripting disabled or filtered as a security MEASURE. For these reasons, it seems to me that very often the most USEFUL and WIDELY applicable solution is going to be one that uses commands and programs which are installed by default -- the lowest common denominator -- even if it involves using those pesky batch commands and techniques instead of the more elegant looking code which alternative methods might exhibit.

You might argue (and many do) that using batch code is a bit like trying to eat spaghetti with a chisel, but if you only have a chisel, and you are hungry, there is a certain pleasure in meeting the challenge. I gather from your comment earlier about "wasting your time" that you dislike batch code, and while I fully respect your right to feel that way, there is a certain perverse pleasure and virtuous feeling to be got from only using the basic tools available. It is allied to the pleasure some people get from writing "one-liners".

Quote from: Dias de verano on April 26, 2008, 02:14:02 AM
You might argue (and many do) that using batch code is a bit like trying to eat spaghetti with a chisel, but if you only have a chisel, and you are hungry, there is a certain pleasure in meeting the challenge. I gather from your comment earlier about "wasting your time" that you dislike batch code, and while I fully respect your right to feel that way, there is a certain perverse pleasure and virtuous feeling to be got from only using the basic tools available. It is allied to the pleasure some people get from writing "one-liners".

no, i won't eat spaghetti with a chisel even if i have a chisel. I can use my hands. Its easier. The same goes to choosing a tool to perform tasks for you easily. Not only does "easily" mean easy to use, but it also means easy to read and maintain code, especially if you have a big environment like the schools you mentioned. This is ultimately called , productivity.


Discussion

No Comment Found