-2

The following code which I use: type C:\users\Public\Temp\%DB%.db | findstr /v /c:"%Remove%" >>newDB.txt works well in removing lines, however it leaves a line with a space instead of removing it all together. How can I avoid this? Here is an example file:

#ITCMDDatabaseFile# 
set $value=1#set user=J#set pass=1234# 
set $value=2#set user=L#set pass=1234#

Edit: %remove% is set to one of the bottom two lines with a for %%A loop. For example's sake us set $value=1#set user=J#set pass=1234#

closed as unclear what you're asking by harrymc, LotPings, n8te, music2myear, phuclv Aug 19 '18 at 15:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I can't reproduce your problem, so please post an example file. And what is your Windows version? – harrymc Jul 28 '18 at 19:36
  • Please edit the question to include an example of the contents of %DB%.db, otherwise it is impossible to answer. – DavidPostill Jul 28 '18 at 19:38
  • Add to your example also content of %Remove% variable, what need to be removed – Alex Jul 28 '18 at 19:40
  • There are no extra spaces on the lines. I tried adding ` type newDB.txt | findstr /v /r /c:"^$" /c:"^\ *$" >newDB.txt` to remove any such lines, however it cleared the whole file. – Mark Deven Jul 28 '18 at 19:40
  • The poster doesn't have the time to make his post useful to others. Voted as "unclear what you're asking". – harrymc Jul 29 '18 at 8:11
1

Ended up having to seperate the steps like so:

    echo. 2>new.txt >nul
    type origfile.txt | findstr /v /c:"Line-I-Want-To-Remove" >>new.txt
    type newDB.txt | findstr /v /r /c:"^$" /c:"^\ *$"  >new2.txt
    type new2.txt >origfile.txt

I think it was because I was in a for loop that the remove blank line wasnt working, however Im still not user why findstr left empty lines.

  • 1
    Very awkward code, but since you don't want to show an example file then this post is not of much use to others. Your combination of calls serves probably just for awkwardly converting end-of-line characters. – harrymc Jul 28 '18 at 19:51
  • Well It's the only way it works for me with the for loops and similar functions, and I don't have time to change everything for someone stumbling across this Q with a similar problem. – Mark Deven Jul 29 '18 at 3:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.