| 1. |
Solve : Batch file to copy & paste text? |
|
Answer» Hello All, I need the batch file to copy from the 0 to the end of the 1st line What 0? I can see five zeroes. The second line is the same as the first line except there are a bunch of spaces and then a 2. What do you mean "paste" it? 99940 E1 -0001.30 # to 99940 E1 -0001.30 2 right now I need a batch file to input the # 2 the very last position on this line. so, this is what the line is right now 99940 E1 -0001.30 I need to have the 2 to be put the very end of that line, so the line will look like 99940 E1 -0001.30999999999999999999999999999992 my thought process was, copy the position after the last 0 to the end of the line. then paste the spaces to where the 9's are with the 2 the very end. i'm sorry for confusing everyone on this.. :-(that will not work the way that i want it to. I have the lines that I'm looking for but I need to have the 2 in position #118 in the text file. in the posting above, it's creating additional spaces and that will not be in the proper format. any idea's on how I can insert the 2 in position #118 of a text file ?What are all those 9s for? Anyhow, the short answer is that you can't directly insert a character into a text file using a simple script. What you can do is read in the original text file, and add the new character to the end of each line, and write the lines out to a new file, which you can then rename to replace the original file. Anyhow, I wouldn't use batch for this, I'd use Visual Basic Script. Quote from: Salmon Trout on December 30, 2011, 12:40:49 PM Anyhow, I wouldn't use batch for this, I'd use Visual Basic Script. I can post a script if you want. Well it would be easy enough to remove the existing spaces at the end of the line and then repad the line with a bunch of spaces and substring that variable to a length of 117 and then put the number at the end. Quote from: Squashman on December 31, 2011, 07:13:21 AM Well it would be easy enough to remove the existing spaces at the end of the line and then repad the line with a bunch of spaces and substring that variable to a length of 117 and then put the number at the end. As posted, each line has TRAILING spaces. I don't know if they exist in the files the OP wishes to process? OP please clarify. If trailing spaces need removing prior to processing, the rtrim function can be used. Also I noted that some of the example lines posted above have one leading space, and some do not. And a hash/pound sign seems to have crept in at position 118. Again, OP please clarify. And all those 9s have not been explained. Anyhow a simple VBScript like the one below should do the needful. Code: [Select]Const ForReading = 1 Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set ReadFile = objFSO.OpenTextFile ("input.txt", ForReading) Set Writefile = objFSO.CreateTextFile ("output.txt", ForWriting) Do While Not ReadFile.AtEndOfStream ReadLine = Readfile.readline WriteLine = ReadLine & Space(117 - LEN(ReadLine)) & "2" wscript.echo "Read line: " & ReadLine wscript.echo "Write line: " & WriteLine Writefile.writeline WriteLine Loop Readfile.Close Writefile.Close |
|