amio Posted July 13, 2008 Share Posted July 13, 2008 [] under all charactersExample: Deletion text content [abcd] under all characters , Does not delete [efgh]--------------------------[abcd]aaaaa bbbbbcc ccccddddd[efgh]eeeeee ffffffffgg gggghhhhhhh---------------------------- After the revision:[efgh]eeeeee ffffffffgg gggghhhhhhh Link to comment Share on other sites More sharing options...
Yzöwl Posted July 13, 2008 Share Posted July 13, 2008 In order to minimise the possibility of completely irrelevant responses to this topic, could you please be a little more specific!What type of file is it? an ini, ASCII, unicode!Is this OS/platform specific?What does the file contain? the aaaaa etc. nonsense can actually waste time.Are you looking for a commandline/script, utility or GUI based solution?Does the availability of third party tools cause problems?Do you need to delete all lines under a section? or would commenting them out be better?What have you tried? Link to comment Share on other sites More sharing options...
amio Posted July 14, 2008 Author Share Posted July 14, 2008 In order to minimise the possibility of completely irrelevant responses to this topic, could you please be a little more specific!What type of file is it? an ini, ASCII, unicode!Is this OS/platform specific?What does the file contain? the aaaaa etc. nonsense can actually waste time.Are you looking for a commandline/script, utility or GUI based solution?Does the availability of third party tools cause problems?Do you need to delete all lines under a section? or would commenting them out be better?What have you tried?Revises windows inf file (ANSI)commandline/scriptTreatment nlite Can not handle some of Link to comment Share on other sites More sharing options...
jaclaz Posted July 14, 2008 Share Posted July 14, 2008 Revises windows inf file (ANSI)commandline/scriptTreatment nlite Can not handle some ofamio, clearly you do have some problems in communicating in English, let's try again .Please post:1) the actual file you need to modify2) the batch or script you used to attempt modifying it3) the file edited by hand as you would like it to have after changesjaclaz Link to comment Share on other sites More sharing options...
amio Posted July 14, 2008 Author Share Posted July 14, 2008 Revises windows inf file (ANSI)commandline/scriptTreatment nlite Can not handle some ofamio, clearly you do have some problems in communicating in English, let's try again .Please post:1) the actual file you need to modify2) the batch or script you used to attempt modifying it3) the file edited by hand as you would like it to have after changesjaclazFor instance DOSNET.INF I would like to use sed or other command Remove:[CmdConsFiles]autochk.exeautofmt.exeKBDFR.DLLKBDGR.DLLKBDHE.DLLKBDIT.DLLKBDRU.DLLKBDSF.DLLKBDSP.DLLKBDSW.DLLKBDUK.DLLKBDUS.DLLKBDUSX.DLLTake [CmdConsFiles] as the key words deletion Link to comment Share on other sites More sharing options...
Yzöwl Posted July 14, 2008 Share Posted July 14, 2008 Ideally this requires a third party tool!One such tool I'd like to suggest is IniMod:IniMod SET .\dosnet.inf CmdConsFiles "" ""I hope this helps! Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 14, 2008 Share Posted July 14, 2008 Ideally this requires a third party tool!I respectfully disagree. While I don't normally like to reinvent the wheel for nothing (e.g. you don't see me try to clone grep or such), this is trivial to do.In fact, one could write a complete clone of IniMod in very little time, in basically any language (JScript/VBScript included)For instance DOSNET.INF I would like to use sed or other command Remove:[CmdConsFiles](lines here)Take [CmdConsFiles] as the key words deletionEasy! Here's a 5 minute quickie that does exactly that, written in vbscript (any other language you prefer, just ask, it would only take a couple minutes to translate):Option ExplicitDim fso, f, filename, section, data, i, s, skipReDim data(500)i=0skip = Falsefilename = Wscript.Arguments(0)section = Wscript.Arguments(1)Set fso = CreateObject("Scripting.FileSystemObject")Set f = fso.OpenTextFile(filename, 1) '1=ForReadingDo Until f.AtEndOfStream s = f.ReadLine If skip=True And Left(s,1) = "[" Then skip=False If s = "[" + section + "]" Then skip=True If skip=False Then data(i) = s i=i+1 If i = UBound(data) Then ReDim Preserve data(i+50) End If If s = "" Then skip = FalseLoopf.CloseSet f = fso.CreateTextFile(filename, True)f.WriteLine Join(data, vbCrLf)f.CloseSave that as delsect.vbs or such, and then to do exactly what you said, you'd use this command line:delsect.vbs DOSNET.INF CmdConsFilesAnd that will delete the [CmdConsFiles] section altogether from DOSNET.INF -- simple as that. Link to comment Share on other sites More sharing options...
Yzöwl Posted July 14, 2008 Share Posted July 14, 2008 If I use your script on this:[abcd]aaaaabbbbbcc ccccddddd[efgh]eeeeeeffffffffgg gggghhhhhhhusing[abcd]aaaaabbbbbcc ccccdddddNote we now have 501 lines whereas my original only had 12. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 14, 2008 Share Posted July 14, 2008 Note we now have 501 lines whereas my original only had 12.Quite strange. It didn't write the empty elements of the array when I ran it on this box (or if it did, I must not have noticed)Easily solved though. Different version that definitely shouldn't have that problem:Option ExplicitDim fso, f, filename, section, data, i, j, s, skipReDim data(500)i=0skip = Falsefilename = Wscript.Arguments(0)section = Wscript.Arguments(1)Set fso = CreateObject("Scripting.FileSystemObject")Set f = fso.OpenTextFile(filename, 1) '1=ForReadingDo Until f.AtEndOfStream s = f.ReadLine If skip=True And Left(s,1) = "[" Then skip=False 'stop skipping, new section reached (w/o a blank line) If s = "[" + section + "]" Then skip=True 'start skipping lines when section reached If skip=False Then data(i) = s i=i+1 If i = UBound(data) Then ReDim Preserve data(i+50) End If If s = "" Then skip = False 'reset once section end reachedLoopf.CloseSet f = fso.CreateTextFile(filename, True)For j = 0 to i-1 f.WriteLine data(j)Nextf.Close Link to comment Share on other sites More sharing options...
Yzöwl Posted July 14, 2008 Share Posted July 14, 2008 Quite strange. It didn't write the empty elements of the array when I ran it on this box (or if it did, I must not have noticed)Easily solved though. Different version that definitely shouldn't have that problem:<snip>That works fine for me crahak! Link to comment Share on other sites More sharing options...
amio Posted July 15, 2008 Author Share Posted July 15, 2008 (edited) Note we now have 501 lines whereas my original only had 12.Quite strange. It didn't write the empty elements of the array when I ran it on this box (or if it did, I must not have noticed)Easily solved though. Different version that definitely shouldn't have that problem:Option ExplicitDim fso, f, filename, section, data, i, j, s, skipReDim data(500)i=0skip = Falsefilename = Wscript.Arguments(0)section = Wscript.Arguments(1)Set fso = CreateObject("Scripting.FileSystemObject")Set f = fso.OpenTextFile(filename, 1) '1=ForReadingDo Until f.AtEndOfStream s = f.ReadLine If skip=True And Left(s,1) = "[" Then skip=False 'stop skipping, new section reached (w/o a blank line) If s = "[" + section + "]" Then skip=True 'start skipping lines when section reached If skip=False Then data(i) = s i=i+1 If i = UBound(data) Then ReDim Preserve data(i+50) End If If s = "" Then skip = False 'reset once section end reachedLoopf.CloseSet f = fso.CreateTextFile(filename, True)For j = 0 to i-1 f.WriteLine data(j)Nextf.CloseThank youWhether to support unicode or utf-8If [] will include a space Will fail For example:[Registry Keys] Edited July 15, 2008 by amio Link to comment Share on other sites More sharing options...
Yzöwl Posted July 15, 2008 Share Posted July 15, 2008 If [] will include a space Will fail For example:[Registry Keys]What about quotes!delsect.vbs MyFile.ini "Section Name" Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 16, 2008 Share Posted July 16, 2008 What about quotes!delsect.vbs MyFile.ini "Section Name"Exactly. That works fine. You have to enclose parameters that have spaces in them with quotes (like for any other cmd line util), otherwise the 2 parts are passed as 2 separate arguments.Whether to support unicode or utf-8Do you have unicode inf files? (I've never seen one as far as I recall).Either ways, you'd only need to make minor changes to the 2 lines that open files to make it work with unicode files, like such:Set f = fso.OpenTextFile(filename, 1, False, -1) '1=ForReading, -1=TristateTrueandSet f = fso.CreateTextFile(filename, True, True)If you have some of both kinds (again, strange...) then you could easily detect it (look for byte order mark, i.e. 0xFF 0xFE for Little Endian, first 2 bytes of the file), then open the file accordingly (wouldn't take 5 minutes to do) Link to comment Share on other sites More sharing options...
amio Posted July 16, 2008 Author Share Posted July 16, 2008 What about quotes!delsect.vbs MyFile.ini "Section Name"Exactly. That works fine. You have to enclose parameters that have spaces in them with quotes (like for any other cmd line util), otherwise the 2 parts are passed as 2 separate arguments.Whether to support unicode or utf-8Do you have unicode inf files? (I've never seen one as far as I recall).Either ways, you'd only need to make minor changes to the 2 lines that open files to make it work with unicode files, like such:Set f = fso.OpenTextFile(filename, 1, False, -1) '1=ForReading, -1=TristateTrueandSet f = fso.CreateTextFile(filename, True, True)If you have some of both kinds (again, strange...) then you could easily detect it (look for byte order mark, i.e. 0xFF 0xFE for Little Endian, first 2 bytes of the file), then open the file accordingly (wouldn't take 5 minutes to do)Thank you, have supported unicodeCan be more functional?Designated Remove [Registry Keys] Arbitrary lineExample:test.vbs test.inf "Registry Keys" HKLM,"SYSTEM\CurrentControlSet\Services\gagp30kx,"%gagp30kx_svcdesc%--------------------------------------------------------------------------------------------test.inf[Registry Keys]aaaHKLM,"SYSTEM\CurrentControlSet\Services\gagp30kx,"%gagp30kx_svcdesc%bbbThe revised:test.inf[Registry Keys]aaabbb---------------------------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 16, 2008 Share Posted July 16, 2008 Thank you, have supported unicodeIt only took a couple minutes to make the changes. No thanks needed Can be more functional?Yes, it could be. But I thought all you wanted was to remove a section. Right now I'm not totally sure what your real needs are (probably more than just removing some lines)I mean, if I add this, is the next request going to be "replacing a line" or such? -- not that there's anything wrong with that! But adding features like that one by one is more work than doing a fully featured app in the first place (this way, you're not deleting half your code every single time to add features, and making big changes in things like parsing command line arguments). I'd be better off to rewrite it all from scratch instead of just making changes to this very simple script all the time, and preferably in another language too (most likely as a C# Console App). It's pretty simple to do. I could make a fancy inf tool (with options to add/delete/replace values, lines and such, joining files, and maybe even simple taking commands from text files or such) and write basic documentation for it (i.e. command line usage, how to escape some characters, etc). I'll put it on my (long) list of pet projects. I'll get around to it sometime... I'm not quite sure just how much interest there is in such a tool, nor how useful it would be, so it's not exactly my top priority for now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now