| 1. |
Solve : Help with batch file- read Nth line in delimited text file? |
|
Answer» Ghost Dog wrote: I have to write a batch file in DOS for work vbscript is probably disabled... Quote from: billrich on September 13, 2009, 01:35:01 AM Gosh, GhostDog is really smart.that sounds sarcastic...but nevertheless...thank you for your compliment. Quote Now GhostDog will demostrate that the *.vbs script fits the defintion of a Batch File.its already done. like that i posted. Quote But please, GhostDog, post your test data and that your *.vbs( VBScript ) script actually works. [/font] since you are so insistent Code: [Select]C:\test>more file 1,0,mess,nothing 2,0,mess,nothing 3,0,mess,nothing 4,0,mess,nothing 5,1,mess,nothing C:\test>cscript /nologo test.vbs 1,0,mess,nothing 2,0,mess,nothing 3,new value,mess,nothing 4,0,mess,nothing 5,1,mess,nothing C:\test>more test.vbs Set objFS=CreateObject("Scripting.FileSystemObject") strFile = "c:\test\file" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfLine linenumber = objFile.Line strLine = objFile.ReadLine If linenumber = 3 Then csv = Split(strLine,",") csv(1) = "new value" strLine = Join(csv,",") End If WScript.Echo strLine Loop objFile.Close 2nd field, line 3 is changed to "new value". does that answer your query?Quote GhostDog wrote: No, the second field is a flag field and must be either 1 or 0. "new value" is the WRONG answer. Your code does not work. You also did not assign the the first field to a variable. Why post code that has not been tested? The OP requested real "Batch code" not incorrect VBScript.Quote from: billrich on September 13, 2009, 10:46:40 AM Your code does not work.yes it does work. Except that I did not provide OP with FULL code. Implementing that flagging system is fairly easy. I want OP to try himself. Code: [Select]if csv(1) = 0 Then csv(1) = 1 end if in fact, there is really no need to do the above, because by changing "new value" in my code to "1", it will still do the same thing... Quote from: billrich You also did not assign the the first field to a variable.if OP has the motivation to learn vbscript, he should be able to do that himself. Quote Why post code that has not been tested?its tested .... you just don't see the point i am making... Quote The OP requested real "Batch code" not incorrect VBScript.once again, define what is real Batch code, accurately. Dude, if you are GOING to provide him your solutions in full , go ahead. Depending on my MOOD, I am not obliged to solve everything for OP. If i really want to nitpick about your code, i would do that, but i will not. for example, Input argument checking, input file format ambiguity, eg your code checks for ",0," .... what if the input data is " , 0 ," therefore, would you just give it a rest... |
|