PDA

View Full Version : Simple Batch file request


Tortanick
11-18-2006, 05:38 AM
I just need a batch file that will allow me to input a text file and remove any occurence of the # charachter, and everything from the # charachter to the end of the line.

rVidia
11-25-2006, 11:34 AM
Sorry about the delayed response, Tortanick; I just noticed your post. Create a batch file with the following code:


@echo off
find /v "#" < originalfile.txt > newfile.txt
del originalfile.txt


For example, here are the contents of originalfile.txt:

Test
#
This is a test
This is # a test #

After running the batch file, these are the contents of newfile.txt:

Test
This is a test

and originalfile.txt is deleted (the line "del originalfile.txt" is optional).

You can see that the line containing # was removed, as was the entire line containing "This is # a test #"

Unfortunately, batch files have no control over deleting certain characters from a text file, although (as above) they can remove a full line containing a certain character/word/phrase.

Let me know if this is what you're looking for,

Ray

Tortanick
11-26-2006, 04:27 AM
sorry but the result should be

Test
This is a test
This is

(delete everything from the first # rather than between them)

rVidia
11-26-2006, 10:30 AM
As said, batch files, unfortunately, have no control over deleting only certain characters from a text file, but they are able to remove a full line containing that certain character. This is why the whole line "This is # a test #" was removed.

kerremelk
11-28-2006, 02:02 PM
hi
some batch and script writers use a little tool called fedit.

note, i haven't used fedit myself, so do not know much more than what its readme tells me.
It might be your answer to your problem, though.

Tortanick
12-01-2006, 12:22 PM
Not much point if I could only delete whole lines, thanks for trying though

kerremelk
12-04-2006, 11:21 PM
hi
what fedit can do

C:\D>fedit
Incorrect syntax! Possible parameters:

-add
Tells Fedit to add LINE.
-rem
Tells Fedit to remove LINE.
-f "some file"
The file to be edited
-l "some text"
The text to be added or removed

When adding, these are additional (optional) parameters:
-a[:co] "some text"
The text will be added after this line
-b[:co] "some text"
The text will be added before this line
-s[:c] "some text"
The text will be added in the section [some text]
-once
The text to be added, will only be added once in the whole file
-create
If the section isn't found, it will be created

When removing, -l supports the parameter [:co], and these additional
(optional) parameters:
-a[:co] "some text"
All instances of the text after this line will be removed.
-b[:co] "some text"
All instances of the text before this line will be removed.
-s[:c] "some text"
All instances of the text in section [some text] will be removed.
-once
The text to be removed, will only be removed once.

The option [:co] means the following:
If you have a parameter -a "some text", Fedit will automatically search for
strings that match it (without being case sensitive). If you want it to be
case sensitive, change it to this:
-a:c "some text"
If you think that 'some text' is contained in a bigger string like 'this is
some text written somewhere', then change it to this:
-a:o "some text"
You can combine both to this:
-a:co "some text"

IMPORTANT: none of the parameters are case sensitive, so for example -rem is
the same as -Rem or -REM. Same thing for -a:co or -A:CO
IMPORTANT: the order of the parameters is unimportant, so:
Fedit -rem -f file -l:co text
Is the same as:
Fedit -f file -l:oc text -rem

C:\D>fedit

kerremelk
12-04-2006, 11:30 PM
hmmm, still not good, i guess.
I don't know wether it can handle wildcard characters.
Programmers at MSFN forums might know.

Tortanick
12-06-2006, 02:45 PM
Or I could just ask at the linux forums, the command line is equal to the GUI over there ;) thanks for trying though.

edit, it works :)

http://www.linuxquestions.org/questions/showthread.php?t=507957