tomasz86 Posted July 27, 2013 Posted July 27, 2013 (edited) SETLOCAL ENABLEDELAYEDEXPANSION FOR /F %%A IN ("!") DO ( SET Line=%%A SET Line=!Line:^^!={#}! ECHO !Line! ) Is there a simple way to make it work? Edited July 27, 2013 by tomasz86
jaclaz Posted July 27, 2013 Posted July 27, 2013 SETLOCAL ENABLEDELAYEDEXPANSIONFOR /F %%A IN ("!") DO ( SET Line=%%A SET Line=!Line:^^!={#}! ECHO !Line!)Is there a simple way to make it work?WHAT EXACTLY do you actually EXPECT that piece of batch to do? If you prefer what do you apply that batch to?And what you would want to have returned by the batch?jaclaz
Yzöwl Posted July 27, 2013 Posted July 27, 2013 SETLOCAL ENABLEDELAYEDEXPANSIONFOR /F %%A IN ("!") DO ( SET Line=%%A SET Line=!Line:^^!={#}! ECHO !Line!)Is there a simple way to make it work?Yes there is; don't enable delayed expansion!SETLOCAL DISABLEDELAYEDEXPANSIONFOR %%A IN (!) DO ( SET Line=%%A CALL SET Line=%%Line:!={#}%% CALL ECHO=%%Line%%)
tomasz86 Posted July 27, 2013 Author Posted July 27, 2013 I've done it this way:FOR /F %%A IN ("!") DO ( CALL :FIX %%A)PAUSEEXIT:FIXSET Line=%1SET Line=%Line:!={#}%ECHO %Line%GOTO :EOF:EOFSo I guess it's impossible with delayed expansion enabled? Using CALL is extremely slow when processing hundreds of lines like that.
Yzöwl Posted July 27, 2013 Posted July 27, 2013 As usual and as jaclaz alluded to you have not provided us with the genuine use for your script.There is no way at all that the file you have posted is what you are actually doing! You have decided that you know better than the people you are asking for help, and that is both incorrect and rude.
tomasz86 Posted July 27, 2013 Author Posted July 27, 2013 I'm sorry for not providing the actual file but I don't think it will really change anything. I'm processing a HTML file and I wanted to replace all special characters with {#}, {##}, etc. This was the original script I tried to use:SETLOCAL ENABLEDELAYEDEXPANSIONFOR /F "delims=" %%A IN (index.html) DO ( SET Line=%%A SET Line=!Line:{#}=^&! SET Line=!Line:{##}=^?! SET Line=!Line:{###}=^<! SET Line=!Line:{####}=^>! SET Line=!Line:{#####}=^^!! SET Line=!Line:{######}=^|! ECHO !Line!)but I encountered the problem just in the very beginning with the first line of the file which is:<!DOCTYPE HTML>
Yzöwl Posted July 27, 2013 Posted July 27, 2013 So are you trying to suggest now that the file you've just posted is what you are actually using?I would strongly suggest that is not the case
gunsmokingman Posted July 27, 2013 Posted July 27, 2013 My two cents worth, VBS would most like be better at processing the HTML line by line without the worry of special characters.
Yzöwl Posted July 27, 2013 Posted July 27, 2013 GSM, you are very correct.You may notice that the file they are pretending to be their finished product is only a small portion of a much larger script. The characters they are replacing are only those which may pose further parsing in a batch file problems. I would be certain based upon the previous help they have received that the intention is to run this routine through to a holding file perform several other batch parsing operations on it then attempt to return the original characters back in later.Despite being aware VBS and small executables such as SED and GSAR and perhaps even lesser known ones like John Stockton's SUBS, tomasz86 is a windows 2000 user and is therefore unable to accept the easy way.
Acheron Posted July 27, 2013 Posted July 27, 2013 (edited) For processing of HTML characters I would choose to use regular expressions. You can use vbscript for this or any other scripting engine like perl or AutoIT.If you insist on using a batch file you better start writing the script from scratch. Copying from online examples can help you, but you need to understand each line of code. Edited July 27, 2013 by Acheron
gunsmokingman Posted July 27, 2013 Posted July 27, 2013 If he was to post the full script that he is using I probably might post the VBS equivalent.Example VBS Script To Process A Text Line By LineDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> File To Work WithDim Text :Text = "Demo Count Down.hta"'-> Check To See If File Exists If Fso.FileExists(Text) Then ReadListText(Fso.GetFile(Text)) Else WScript.Echo "Missing : " & Text End If '-> Function To Process Line By Line Text Files Function ReadListText(T) Dim i, j, Ts Set Ts = Fso.OpenTextFile(T.Path, 1) i = Ts.ReadAll For Each j In Split(i,vbCrLf) WScript.Echo j Next End Function
tomasz86 Posted July 27, 2013 Author Posted July 27, 2013 So are you trying to suggest now that the file you've just posted is what you are actually using? I would strongly suggest that is not the caseThere's no larger script this time. The script posted above is the only one I tried to use on the HTML file but then realised that it didn't work with exclamation marks. That's why I posted the question Once again, this is a completely different thing than the other script about merging updates. It's got nothing to do with that. I'm writing a script to process a HTML file in order to remove some parts from it. I've got no other issues with it. I just wanted to ask whether it was possible to process exclamation marks with delayed expansion enabled but it seems that the simplest way to solve the problem will be just disable it and use CALL. Anyhow, thank you for the answer (post #3).
Yzöwl Posted July 27, 2013 Posted July 27, 2013 So are you trying to suggest now that the file you've just posted is what you are actually using?I would strongly suggest that is not the caseThere's no larger script this time. The script posted above is the only one I tried to use on the HTML file but then realised that it didn't work with exclamation marks. That's why I posted the question Once again, this is a completely different thing than the other script about merging updates. It's got nothing to do with that. I'm writing a script to process a HTML file in order to remove some parts from it. I've got no other issues with it. I just wanted to ask whether it was possible to process exclamation marks with delayed expansion enabled but it seems that the simplest way to solve the problem will be just disable it and use CALL. Anyhow, thank you for the answer (post #3).The script you posted echoes replacements to the console window only, it most certainly does not remove parts of the html file. A html file without its opening and closing tag symbols isn't really a html file.You asked for help with a specific problem when the problem you had was something different. I gave you a solution to replace a single character in a single character string with three specific characters. You then rejected my solution because you'd decided not to inform us that you were intending to replace several different characters in an entire file with strings of varying lengths. Our Members do not have to be rocket scientists to see that the characters you were intending to replace were those which pose problems to batch script parsing, and that the process you posted if not currently part of a larger script is intended to be so.You are thinking through a task in small pieces without first looking at the entire picture. Whilst it may not be part of the merging .inf files topic, it certainly has the hall marks of taking light years to achieve a goal which could have been achieved quickly with the full information from the start.
tomasz86 Posted July 28, 2013 Author Posted July 28, 2013 (edited) I didn't ask for help with removing parts from the HTML file because I can do it myself. The only problem I had was that exclamation marks were absent from the final file due to delayed expansion enabled, and that's why I asked the original question. You actually gave the answer already which is: Yes there is; don't enable delayed expansion! and I modified the script so that it works with delayed expansion disabled. I was just curious whether it was possible to somewhat escape the exclamation mark while leaving delayed expansion enabled. Edited July 28, 2013 by tomasz86
jaclaz Posted July 28, 2013 Posted July 28, 2013 To me it is still the SAME issue already seen on the good ol' "merge and join" thread. In there I used for simplicity a pre (and post) processing with gsar for substituting characters that created issues in the batch processing. I don't see in which way this is different. In my perverted mind, if you can do without an external tool/app, that is very good , but in this specific case a small .exe like gsar is better (IMHO) than any complexity in batch code and once you have it anyway it is better to re-use it as much as you can (economy of scale , the cost - in bytes - of the tool is amortized faster). jaclaz
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now