Jump to content

Deletion text content


Recommended Posts

[] under all characters

Example: Deletion text content [abcd] under all characters , Does not delete [efgh]

--------------------------

[abcd]

aaaaa

bbbbb

cc cccc

ddddd

[efgh]

eeeeee

ffffffff

gg gggg

hhhhhhh

---------------------------- After the revision:

[efgh]

eeeeee

ffffffff

gg gggg

hhhhhhh

Link to comment
Share on other sites


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

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/script

Treatment nlite Can not handle some of

Link to comment
Share on other sites

Revises windows inf file (ANSI)

commandline/script

Treatment nlite Can not handle some of

amio, clearly you do have some problems in communicating in English, let's try again :).

Please post:

1) the actual file you need to modify

2) the batch or script you used to attempt modifying it

3) the file edited by hand as you would like it to have after changes

jaclaz

Link to comment
Share on other sites

Revises windows inf file (ANSI)

commandline/script

Treatment nlite Can not handle some of

amio, clearly you do have some problems in communicating in English, let's try again :).

Please post:

1) the actual file you need to modify

2) the batch or script you used to attempt modifying it

3) the file edited by hand as you would like it to have after changes

jaclaz

For instance DOSNET.INF

I would like to use sed or other command Remove:

[CmdConsFiles]

autochk.exe

autofmt.exe

KBDFR.DLL

KBDGR.DLL

KBDHE.DLL

KBDIT.DLL

KBDRU.DLL

KBDSF.DLL

KBDSP.DLL

KBDSW.DLL

KBDUK.DLL

KBDUS.DLL

KBDUSX.DLL

Take [CmdConsFiles] as the key words deletion

Link to comment
Share on other sites

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 deletion

Easy! 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 Explicit
Dim fso, f, filename, section, data, i, s, skip

ReDim data(500)
i=0
skip = False
filename = Wscript.Arguments(0)
section = Wscript.Arguments(1)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, 1) '1=ForReading
Do 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 = False
Loop
f.Close
Set f = fso.CreateTextFile(filename, True)
f.WriteLine Join(data, vbCrLf)
f.Close

Save that as delsect.vbs or such, and then to do exactly what you said, you'd use this command line:

delsect.vbs DOSNET.INF CmdConsFiles

And that will delete the [CmdConsFiles] section altogether from DOSNET.INF -- simple as that.

Link to comment
Share on other sites

If I use your script on this:

[abcd]
aaaaa
bbbbb
cc cccc
ddddd

[efgh]
eeeeee
ffffffff
gg gggg
hhhhhhh

using

[abcd]
aaaaa
bbbbb
cc cccc
ddddd















































































































































































































































































































































































































































































































Note we now have 501 lines whereas my original only had 12.

Link to comment
Share on other sites

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 Explicit
Dim fso, f, filename, section, data, i, j, s, skip

ReDim data(500)
i=0
skip = False
filename = Wscript.Arguments(0)
section = Wscript.Arguments(1)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, 1) '1=ForReading
Do 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 reached
Loop
f.Close
Set f = fso.CreateTextFile(filename, True)
For j = 0 to i-1
f.WriteLine data(j)
Next
f.Close

Link to comment
Share on other sites

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

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 Explicit
Dim fso, f, filename, section, data, i, j, s, skip

ReDim data(500)
i=0
skip = False
filename = Wscript.Arguments(0)
section = Wscript.Arguments(1)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, 1) '1=ForReading
Do 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 reached
Loop
f.Close
Set f = fso.CreateTextFile(filename, True)
For j = 0 to i-1
f.WriteLine data(j)
Next
f.Close

Thank you

Whether to support unicode or utf-8

If [] will include a space Will fail

For example:

[Registry Keys]

Edited by amio
Link to comment
Share on other sites

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-8

Do 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=TristateTrue

and

Set 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

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-8

Do 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=TristateTrue

and

Set 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 unicode

Can be more functional?

Designated Remove [Registry Keys] Arbitrary line

Example:

test.vbs test.inf "Registry Keys" HKLM,"SYSTEM\CurrentControlSet\Services\gagp30kx,"%gagp30kx_svcdesc%

--------------------------------------------------------------------------------------------

test.inf

[Registry Keys]

aaa

HKLM,"SYSTEM\CurrentControlSet\Services\gagp30kx,"%gagp30kx_svcdesc%

bbb

The revised:

test.inf

[Registry Keys]

aaa

bbb

----------------------------------------------------------------------------------------------

Link to comment
Share on other sites

Thank you, have supported unicode

It 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...