Computing.Net > Forums > Programming > Batch remove line after searchstrin

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch remove line after searchstrin

Reply to Message Icon

Name: Morphin
Date: July 18, 2008 at 07:02:08 Pacific
OS: Div
CPU/Ram: Div
Product: Div
Comment:

Hi
I would like to delete the next line (not empty) in a file following a search string. I can find the line with the string with "FOR /F", but i need to delete the next line of this file.

Andy



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 19, 2008 at 13:29:37 Pacific
Reply:

"OS: Div"

Help me out here.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Morphin
Date: July 20, 2008 at 22:34:48 Pacific
Reply:

Hi

Sorry i don't unterstand. What's the meaning of "OS: DIV"?
Regards
Andy

Andy


0

Response Number 3
Name: Mechanix2Go
Date: July 21, 2008 at 03:18:30 Pacific
Reply:

In order to write a batch, one would need to know the OS.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Morphin
Date: July 21, 2008 at 03:24:39 Pacific
Reply:

Oh
Sorry, Windows 2003 Server, I thought that i wrote this on my preferences.
-> DOS BATCH

Andy

Andy


0

Response Number 5
Name: Mechanix2Go
Date: July 21, 2008 at 05:30:00 Pacific
Reply:

@echo off > newfile
setLocal EnableDelayedExpansion

for /f "tokens=1 delims=[] " %%a in ('find /n "string" ^< myfile') do (
set /a N=%%a+1
)
for /f "tokens=1* delims=[] " %%a in ('find /n /v "" ^< myfile') do (
if not %%a equ !N! echo %%b >> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: Morphin
Date: July 24, 2008 at 04:29:52 Pacific
Reply:

Hi

Thank's very much. You are wonderful!
Regards
Andy

Andy


0

Response Number 7
Name: Morphin
Date: July 25, 2008 at 01:13:22 Pacific
Reply:

Hi
I had to change your script a little bit.
1) i also want to remove the line with the string that i searched and 2) the file has lines with "[sometext]" inside. So i had change "find" to "findstr"
--------------------
SET OutFile=sidtest.conf
SET Identifier=ictr1t

for /f "tokens=1 delims=:" %%a in ('findstr /n "%Identifier%" ^< sid.conf') do (
set /a N=%%a+1
)

for /f "tokens=1* delims=:" %%a in ('findstr /n /v %Identifier% ^< sid.conf') do (
if not %%a equ !N! echo %%b >> %OutFile%
)
---------------------
Now i have the problem if it has "empty" lines in the file it will be replaced with "ECHO is off."
->how do i supress this?
Thank you very much for your help
Regards
Andy

Andy


0

Response Number 8
Name: Morphin
Date: July 25, 2008 at 01:38:57 Pacific
Reply:

Hi
I have found the solution:
echo/%%b will do the trick

Thank's
Andy

Andy


0

Sponsored Link
Ads by Google
Reply to Message Icon

Program to add filename a... VBScript to login into se...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch remove line after searchstrin

Remove Lines of text www.computing.net/answers/programming/remove-lines-of-text/19354.html

Batch: Delete lines in txt / extrac www.computing.net/answers/programming/batch-delete-lines-in-txt-extrac/16170.html

Batch file exits after GET command www.computing.net/answers/programming/batch-file-exits-after-get-command/15735.html