Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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.filthe 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.

@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 felicityM2

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

![]() |
Copying Files from Nested...
|
get c:\ space
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |