Create a batch file to read a file

November 18, 2010 at 14:09:38
Specs: Windows XP
Hello Friends...

Can anyone help me in creating a .bat file... I am nowise in writing the batch files

I need to read a text file .... For example the file looks something like this....

Virus in server 123 with 81.1.2.0 IP address
The Operation was success in Line 33
The Operation was success in Line 34
The Operation was success in Line 35
Virus in server 345 with 81.1.2.0 IP address
The Operation was success in Line 36
The Operation was success in Line 37
The Operation was success in Line 38
Virus in server 678 with 81.1.2.0 IP address
The Operation was success in Line 39
The Operation was success in Line 40

So, as soon as its see a string "Virus in Server" it should read till the end of the line and copy to another text file..

Text File should look something like this ....

Virus in server 123 with 81.1.2.0 IP address
Virus in server 345 with 81.1.2.0 IP address
Virus in server 678 with 81.1.2.0 IP address

Please can anyone help how to write a batch file for this kind of scenario....


See More: Create a batch file to read a file

Report •


#1
November 18, 2010 at 15:53:37
FIND "Virus in Server" "P:\a\t\h\FileName.txt" >> NewFile.txt

Can I put a question here?


Report •

#2
November 18, 2010 at 16:02:44
will FIND only copy "Virus From Server" string or till the End of the Line will it copy ?

do i need to just type this line in an textpad and save it as .bat file?


Report •

#3
November 18, 2010 at 18:59:20
No, It will copy the whole line. However I wasn't thinking when I posted that earlier because the find commend has a heading, so you will need to change the command slightly to this:

FOR /f "tokens=* skip=2" %%a IN ('FIND "Virus in Server" "P:\a\t\h\FileName.txt"') DO ECHO %%a>>NewFile.txt

You can either save it as a .bat, or run it from the prompt.

NOTE: If yo decide to run from the prompt, change "%%a" to "%a".

Can I put a question here?


Report •

Related Solutions

#4
November 19, 2010 at 07:09:21
I've got a .csv file seperated into two columns. If column B contains the line "added c:\windows\" then I need the rest of column B, and the first 7 or 8 characters of column A put into a text file. I've tried manipulating what's here but without any luck so far. Any help would be appreciated. Thanks!
Jake

Report •

#5
November 19, 2010 at 09:23:58
can you post few lines (or similer) here so we can emulate the scenario.

Subhash Chandra.


Report •

#6
November 19, 2010 at 09:52:08
Thanks Alotttttttttttt Matt............

Report •


Ask Question