Prevent removing of blank lines....

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Prevent removing of blank lines....

#1 Post by pditty8811 » 21 Feb 2013 15:58

I have some code here, but it removes all the blank lines in 2.txt. How to prevent this?

Thank you.

Code: Select all

@echo off

copy 2.txt 2.txt-backup

setlocal enableDelayedExpansion

>2.txt (
    for /f "delims=" %%A in (2.txt-backup) do (
        ( echo !ln!| findstr "^Type=206$" >NUL && (
            set ln=ln
        ) ) || (
            set "ln=%%A"
            if "!ln:~0,6!"=="Class=" (
                findstr /c:"ClassName=!ln:~6!" Log_*.txt >null && (
                    echo Class=ShipDummy
                    set "ln=Type=206"
                )
            )
            echo !ln!
        )
    )
)

mfm4aa
Posts: 70
Joined: 13 Feb 2013 14:02
Location: Europe

Re: Prevent removing of blank lines....

#2 Post by mfm4aa » 21 Feb 2013 18:16

One short suggestion:

Code: Select all

@echo off

copy 2.txt 2.txt-backup

setlocal enableDelayedExpansion

>2.txt (
   for /f "tokens=1*delims=:" %%A in ('type 2.txt-backup ^| findstr /n $') do (
      ( echo !ln!| findstr "^Type=206$" >NUL && (
            set ln=ln
        ) ) || (
            set "ln=%%B"
            if "!ln:~0,6!"=="Class=" (
                findstr /c:"ClassName=!ln:~6!" Log_*.txt >null && (
                    echo Class=ShipDummy
                    set "ln=Type=206"
                )
            )
            echo.!ln!
        )
    )
)

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Prevent removing of blank lines....

#3 Post by pditty8811 » 21 Feb 2013 19:31

Thank you very much.

Now, what if I wanted to use as the variable, instead of what came after ClassName= in 1.txt, what came in between (for example):

EntryText=Ship sunk!|Grid AO 77| Grab variable HERE,

So grab after the text line ending with the second | and before the comma.

The text line will be the same EXCEPT after Grid there could be a word or a different two pair of letters and numbers.


So this is what I am trying to use as a variable, what is in between:

EntryText=Ship sunk!|Grid (Any combination of letters or words followed by a| This is what I'd like to replace within the code after ClassName= and a comma.

So grab in between the second | and the comma

Post Reply