Computing.Net > Forums > Programming > Batch Program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch Program

Reply to Message Icon

Name: christian56
Date: October 30, 2009 at 05:01:27 Pacific
OS: Windows XP
Product: Intel celeron / 4400
Subcategory: Batch
Comment:

Hi there,

I was wondering to know if it is possible to create a code batch, which can find information "#" in certain lines and delete them. The real challenge is to idintify the first and the last line of the text and not delete them, even they contain the character "#".

This text is like this:

#dfd2121213131313df#
gdgs5444646544654654
dsgdsg54545456454545
dsfsda54545445646552
#sdfsd5454646546544#
#sdf524545654446546#
fdsf2121212111311313
sdf21231211321311213
dfsd1123121212131212
#sadfsaf21212112312#

Tank you for any help you can provide.




Sponsored Link
Ads by Google

Response Number 1
Name: nbrane
Date: October 31, 2009 at 00:02:45 Pacific
Reply:

something *like* (i don't know syntax yet)

set n=0
for .. %d in (test.fil) do (
if n=0 echo %d > out.fil
if n>0 ( echo %d | find /v "#" >> out.fil )
set %x=%d
set n+=1
)
echo %x >> out.fil

the syntax is all wrong, but hopefully the gist is corr.
other's posts should be much more helpful.

ps: i'm about sure there's easier/more efficient way to do this code-wise.


1

Response Number 2
Name: Mechanix2Go
Date: October 31, 2009 at 04:01:26 Pacific
Reply:

@echo off > newfile & setLocal enableDELAYedexpansion

set N=
set T=

for /f "tokens=* delims= " %%a in (myfile) do (
set /a T+=1
)

for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
if !N! equ 1 (
> newfile echo %%a
)
if !N! gtr 1 if !N! lss !T! (
echo %%a | find /v "#" >> newfile
)
if !N! equ !T! (
>> newfile echo %%a
)
)


=====================================
Helping others achieve escape felicity

M2


1

Response Number 3
Name: christian56
Date: November 1, 2009 at 06:36:26 Pacific
Reply:

Thank you so much, your code worked perfectly!

I just had to include a line in the end:

@echo off > newfile & setLocal enableDELAYedexpansion

set N=
set T=

for /f "tokens=* delims= " %%a in (entrega.txt) do (
set /a T+=1
)

for /f "tokens=* delims= " %%a in (entrega.txt) do (
set /a N+=1
if !N! equ 1 (
> newfile echo %%a
)
if !N! gtr 1 if !N! lss !T! (
echo %%a | find /v "#" >> newfile
)
if !N! equ !T! (
>> newfile echo %%a
)
)

copy newfile entrega.txt & del newfile


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Copying Files from Nested... get c:\ space


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batch Program

Advanced batch program www.computing.net/answers/programming/advanced-batch-program/14439.html

Batch Programming www.computing.net/answers/programming/batch-programming/3213.html

Batch Programming www.computing.net/answers/programming/batch-programming/15718.html