Discussion:
Replace line in a txt file with missing value
(too old to reply)
Zaidy036
2024-01-08 02:44:44 UTC
Permalink
Windows 10 Pro

My sample.txt is similar to the following up to 50 lines:
SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 7 :
SSID 8 : XFINITY
SSID 9 : A440

"FOR /D %%S IN ..." then scans sample.txt for specific names to make
result.txt.
--PROBLEM: If a line has nothing after "SSID nn :" then my batch exits.

The sequence of numbers must be complete and I have tried many ways but
failed to replace any random line without an "SSID nn :" entry with
"SSID nn : None".

Any suggestions?
JJ
2024-01-08 05:03:59 UTC
Permalink
Post by Zaidy036
Windows 10 Pro
SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 8 : XFINITY
SSID 9 : A440
"FOR /D %%S IN ..." then scans sample.txt for specific names to make
result.txt.
--PROBLEM: If a line has nothing after "SSID nn :" then my batch exits.
The sequence of numbers must be complete and I have tried many ways but
failed to replace any random line without an "SSID nn :" entry with
"SSID nn : None".
Any suggestions?
Can't fix code if you don't provide it.

Chances are that, you're not double quoting a variable when needed. So, when
the variable content has space(s) in it, the space(s) in the expanded string
will be treated as a command line argument separator.

The file should be done like this.

@echo off
setlocal enabledelayedexpansion
set "input=source.txt"
set "output=result.txt"
Post by Zaidy036
"%output%" (
for /f "usebackq tokens=1,2* delims=:" %%A in ("%input%") do (
rem check for empty/white-spaces string
2>nul set /a "x=1*%%B1"
if !x! == 0 (
rem not empty or only has white-spaces
echo %%A:%%B
) else echo %%A: None
)
)
Zaidy036
2024-01-08 18:15:54 UTC
Permalink
Post by JJ
Post by Zaidy036
Windows 10 Pro
SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 8 : XFINITY
SSID 9 : A440
"FOR /D %%S IN ..." then scans sample.txt for specific names to make
result.txt.
--PROBLEM: If a line has nothing after "SSID nn :" then my batch exits.
The sequence of numbers must be complete and I have tried many ways but
failed to replace any random line without an "SSID nn :" entry with
"SSID nn : None".
Any suggestions?
Can't fix code if you don't provide it.
Chances are that, you're not double quoting a variable when needed. So, when
the variable content has space(s) in it, the space(s) in the expanded string
will be treated as a command line argument separator.
The file should be done like this.
@echo off
setlocal enabledelayedexpansion
set "input=source.txt"
set "output=result.txt"
Post by Zaidy036
"%output%" (
for /f "usebackq tokens=1,2* delims=:" %%A in ("%input%") do (
rem check for empty/white-spaces string
2>nul set /a "x=1*%%B1"
if !x! == 0 (
rem not empty or only has white-spaces
echo %%A:%%B
) else echo %%A: None
)
)
Sorry, did not mean to cause further confusion.

_JJ (total entries in list) and _NN (multi-run counter) are set before

SET /A _X=0
:_RepeatX
SET /A _X=%_X% + 1
FOR /D %%S IN ("Guest" "Residents" "ResidentsA" "Residents 5") DO (
FINDSTR /C:"SSID %_X% : %%~S" F:\_%_NN%NetworkB.txt >> F:\_%_NN%NetworkL.txt
)
IF NOT %_X%==%_JJ% && GOTO _RepeatX

(removed "FOR /L" to simplify for test)

"usebackq tokens" is what I am missing so thanks for bringing to my
attention. I will learn about applying it for the above or for making
F:\_%_NN%NetworkB.txt
JJ
2024-01-09 01:21:31 UTC
Permalink
Post by Zaidy036
Sorry, did not mean to cause further confusion.
_JJ (total entries in list) and _NN (multi-run counter) are set before
SET /A _X=0
:_RepeatX
SET /A _X=%_X% + 1
FOR /D %%S IN ("Guest" "Residents" "ResidentsA" "Residents 5") DO (
FINDSTR /C:"SSID %_X% : %%~S" F:\_%_NN%NetworkB.txt >> F:\_%_NN%NetworkL.txt
)
IF NOT %_X%==%_JJ% && GOTO _RepeatX
(removed "FOR /L" to simplify for test)
"usebackq tokens" is what I am missing so thanks for bringing to my
attention. I will learn about applying it for the above or for making
F:\_%_NN%NetworkB.txt
Also initialize the _JJ variable. Don't leave it empty/unassigned.
Initialize it with 0.
Zaidy036
2024-01-10 03:23:02 UTC
Permalink
Post by JJ
Post by Zaidy036
Sorry, did not mean to cause further confusion.
_JJ (total entries in list) and _NN (multi-run counter) are set before
SET /A _X=0
:_RepeatX
SET /A _X=%_X% + 1
FOR /D %%S IN ("Guest" "Residents" "ResidentsA" "Residents 5") DO (
FINDSTR /C:"SSID %_X% : %%~S" F:\_%_NN%NetworkB.txt >> F:\_%_NN%NetworkL.txt
)
IF NOT %_X%==%_JJ% && GOTO _RepeatX
(removed "FOR /L" to simplify for test)
"usebackq tokens" is what I am missing so thanks for bringing to my
attention. I will learn about applying it for the above or for making
F:\_%_NN%NetworkB.txt
Also initialize the _JJ variable. Don't leave it empty/unassigned.
Initialize it with 0.
Of course just look at second line starting with _JJ

I have a problem I cannot solve:

---This one line in an Admin CMD window works:
FOR /F "TOKENS=1,2 DELIMS=:" %A IN (F:\_%_NN%NW-B.txt) DO (IF "%B"==" "
ECHO %A >> F:\_%_NN%NW-N.txt)

---In a batch running as Admin using %% the batch crashes:
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_%_NN%NW-B.txt") DO
(IF "%B"==" " ECHO %%A >> F:\_%_NN%NW-N.txt)

How do I make the batch work?
Zaidy036
2024-01-10 03:37:09 UTC
Permalink
Post by Zaidy036
Post by JJ
Post by Zaidy036
Sorry, did not mean to cause further confusion.
_JJ (total entries in list) and _NN (multi-run counter) are set before
SET /A _X=0
:_RepeatX
SET /A _X=%_X% + 1
FOR /D %%S IN ("Guest" "Residents" "ResidentsA" "Residents 5") DO (
FINDSTR /C:"SSID %_X% : %%~S" F:\_%_NN%NetworkB.txt >>
F:\_%_NN%NetworkL.txt
)
IF NOT %_X%==%_JJ% && GOTO _RepeatX
(removed "FOR /L" to simplify for test)
"usebackq tokens" is what I am missing so thanks for bringing to my
attention. I will learn about applying it for the above or for making
F:\_%_NN%NetworkB.txt
Also initialize the _JJ variable. Don't leave it empty/unassigned.
Initialize it with 0.
Of course just look at second line starting with _JJ
FOR /F "TOKENS=1,2 DELIMS=:" %A IN (F:\_%_NN%NW-B.txt) DO (IF "%B"==" "
ECHO %A >> F:\_%_NN%NW-N.txt)
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_%_NN%NW-B.txt") DO
(IF "%B"==" " ECHO %%A >> F:\_%_NN%NW-N.txt)
How do I make the batch work?
Sorry, I have been trying so many tests got confused but BOTH with and
without USEBACKQ the batch crashes and the Admin CMD window only works
with USEBACKQ.
Herbert Kleebauer
2024-01-10 09:29:26 UTC
Permalink
Post by Zaidy036
FOR /F "TOKENS=1,2 DELIMS=:" %A IN (F:\_%_NN%NW-B.txt) DO (IF "%B"==" "
ECHO %A >> F:\_%_NN%NW-N.txt)
Is _NN a variable and %_NN% its content or is the % in
_%_NN%NW-N.txt part of the file name (you should never use
a % in a file name. In a batch file you have to double the %.
Zaidy036
2024-01-10 17:14:19 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
FOR /F "TOKENS=1,2 DELIMS=:" %A IN (F:\_%_NN%NW-B.txt) DO (IF "%B"==" "
ECHO %A >> F:\_%_NN%NW-N.txt)
Is _NN a variable and %_NN% its content or is the % in
_%_NN%NW-N.txt part of the file name (you should never use
a % in a file name. In a batch file you have to double the %.
That complication is so the batch can do multiple runs but still ID data
to review. I will simplify with "outside" run numbering and renaming
data files after the main part of the batch like:

SET _NN=0
:_DoIt
SET /A _NN=%_NN% + 1
[ batch cmds without %_NN% ]
[ REN F:\xxxx.xxx to %_NN%xxxx.xxx ]
[ run again will be manual using CHOICE GOTO _DoIt]
Herbert Kleebauer
2024-01-10 18:30:04 UTC
Permalink
Post by Zaidy036
That complication is so the batch can do multiple runs but still ID data
to review. I will simplify with "outside" run numbering and renaming
SET _NN=0
:_DoIt
SET /A _NN=%_NN% + 1
[ batch cmds without %_NN% ]
[ REN F:\xxxx.xxx to %_NN%xxxx.xxx ]
[ run again will be manual using CHOICE GOTO _DoIt]
Just tell us, what you really want to do. You said you have
an input file like:

My sample.txt is similar to the following up to 50 lines:
SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 7 :
SSID 8 : XFINITY
SSID 9 : A440


What exactly should the batch do? Generate an output file?
If yes, what should be the content of the output file?
Zaidy036
2024-01-10 20:59:30 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
That complication is so the batch can do multiple runs but still ID data
to review. I will simplify with "outside" run numbering and renaming
SET _NN=0
:_DoIt
SET /A _NN=%_NN% + 1
[ batch cmds without %_NN% ]
[ REN F:\xxxx.xxx to %_NN%xxxx.xxx ]
[ run again will be manual using CHOICE GOTO _DoIt]
Just tell us, what you really want to do. You said you have
SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 8 : XFINITY
SSID 9 : A440
What exactly should the batch do? Generate an output file?
If yes, what should be the content of the output file?
Sorry but I try to learn and after a failure and searching in vain for a
solution I ask here. I build my batches a step at a time ending in ECHO(
& CMD /K so I can look at the new results.

I am not asking here for a complete solution to my goal. The problem is
that the input file has SSIDs with blank names which I must fill in a
dummy name to eliminate following crashes.
- F:\_NW-B.txt is the input file example above
- F:\_NW-N.txt is a list of blank SSID names in _NW-B

I simplified by removal of %_NN% and:
- This current last one liner crashes the batch:
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (IF
"%B"==" " ECHO %%A >> F:\_NW-N.txt)

- But this one liner works (same but %%A now %A) in Admin-CMD using the
batch result files:
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %A IN ("F:\_NW-B.txt") DO (IF
"%B"==" " ECHO %A >> F:\_NW-N.txt)

Why does it work in Admin-CMD BUT not in batch?
Herbert Kleebauer
2024-01-10 23:41:14 UTC
Permalink
Post by Zaidy036
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (IF
"%B"==" " ECHO %%A >> F:\_NW-N.txt)
Move "IF" to the next line, double the % and remove the space from "%B"==" "

FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (
IF "%%B"=="" ECHO %%A >> F:\_NW-N.txt)


But why do you use USEBACKQ?
Zaidy036
2024-01-11 02:09:14 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (IF
"%B"==" " ECHO %%A >> F:\_NW-N.txt)
Move "IF" to the next line, double the % and remove the space from "%B"==" "
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (
IF "%%B"=="" ECHO %%A >> F:\_NW-N.txt)
But why do you use USEBACKQ?
Because my experience if runs in Admin-CMD will also run in batch. Tried
without usebackq and errors.

"%B"==" " space required can see when run with ...DO (ECHO "%A" "%B")

Moving to second line does not work in Admin-CMD and only benefit is
shorter lines in the script.

As a further test I ran only that one command in both ADMIN and nonADMIN
Batches and they also crashed,

Did you test your suggestions in Admin-CMD?

Why does it work in Admin-CMD BUT not in a batch?
Herbert Kleebauer
2024-01-11 07:28:35 UTC
Permalink
Post by Zaidy036
Did you test your suggestions in Admin-CMD?
I executed the following batch file:

::@echo off

FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("_NW-B.txt") DO (
IF "%%B"=="" ECHO %%A >> _NW-N.txt)


With the input file _NW-B.txt:

SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 7 :
SSID 8 : XFINITY
SSID 9 : A440


and got the output file _NW-N.txt:

SSID 7
Post by Zaidy036
Why does it work in Admin-CMD BUT not in a batch?
What do you mean with "Admin-CMD"? But in a batch
the above code works here.
Zaidy036
2024-01-11 13:25:46 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
Did you test your suggestions in Admin-CMD?
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("_NW-B.txt") DO (
IF "%%B"=="" ECHO %%A >> _NW-N.txt)
SSID 1 : Residents 5
SSID 2 : HSL2
SSID 3 : AscomI62
SSID 4 : Guest
SSID 5 : ResidentsA
SSID 6 : ResidentsB
SSID 8 : XFINITY
SSID 9 : A440
SSID 7
Post by Zaidy036
Why does it work in Admin-CMD BUT not in a batch?
What do you mean with "Admin-CMD"? But in a batch
the above code works here.
How do you run successfully without using the full paths to the files?

My files are on F:\ so I use full path.

"Admin-CMD" means I open a CMD window in administrative mode, which was
required to make _NW-B.txt in previous commands, and use the command
leaving off the second "%" as required and F:\_NW-B.txt in place.

Could you retest placing the files in another location and using full paths?
Herbert Kleebauer
2024-01-11 13:48:20 UTC
Permalink
Post by Zaidy036
How do you run successfully without using the full paths to the files?
My files are on F:\ so I use full path.
I don't have a F: so I put the text file in the same directory as the
batch file.
Post by Zaidy036
Could you retest placing the files in another location and using full paths?
I now used d: instead of f:, works without any problem.


::@echo off

FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("D:\_NW-B.txt") DO (
IF "%%B"=="" ECHO %%A >> D:\_NW-N.txt)
Zaidy036
2024-01-11 14:12:28 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
How do you run successfully without using the full paths to the files?
My files are on F:\ so I use full path.
I don't have a F: so I put the text file in the same directory as the
batch file.
Post by Zaidy036
Could you retest placing the files in another location and using full paths?
I now used d: instead of f:, works without any problem.
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("D:\_NW-B.txt") DO (
IF "%%B"=="" ECHO %%A >> D:\_NW-N.txt)
Thanks.

I copied your command string into a batch with only that to run. Changed
D: to F: and it crashed in both non-Admin and Admin modes.

I guess it is time to SFC even though all my other programs and batches
run fine.
Herbert Kleebauer
2024-01-11 14:45:22 UTC
Permalink
Post by Zaidy036
I copied your command string into a batch with only that to run. Changed
D: to F: and it crashed in both non-Admin and Admin modes.
What do you mean with "crashed"? What exactly happens?
There should be an error message.
Kenny McCormack
2024-01-11 14:46:40 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
I copied your command string into a batch with only that to run. Changed
D: to F: and it crashed in both non-Admin and Admin modes.
What do you mean with "crashed"? What exactly happens?
There should be an error message.
I assumed it meant that he had to power-cycle the computer.

That usually what "crashed" means.
--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Aspergers
Zaidy036
2024-01-11 15:09:20 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
I copied your command string into a batch with only that to run. Changed
D: to F: and it crashed in both non-Admin and Admin modes.
What do you mean with "crashed"? What exactly happens?
There should be an error message.
Batch window closed and _NW-N.txt not generated. PC did not require
reboot or power cycle.

SFC = System File Checker
Herbert Kleebauer
2024-01-11 15:30:31 UTC
Permalink
Post by Zaidy036
Batch window closed and _NW-N.txt not generated.
Did you start the batch with a double click in explorer?
Then insert a pause at the end of the batch to see the
error message. Or better start the batch within an open
CMD window

If you started the batch within an opened CMD window
and the CMD window is closed when you execute the batch,
then you have a seriously problem. In this case simplify
the batch code until it doesn't crash and then add
code until you find the critical part of the code.
Zaidy036
2024-01-11 16:03:56 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
Batch window closed and _NW-N.txt not generated.
Did you start the batch with a double click in explorer?
Then insert a pause at the end of the batch to see the
error message. Or better start the batch within an open
CMD window
If you started the batch within an opened CMD window
and the CMD window is closed when you execute the batch,
then you have a seriously problem. In this case simplify
the batch code until it doesn't crash and then add
code until you find the critical part of the code.
basically that is what I did and the addition of the cmd shown closes
the batch window but when run with an open cmd window and NOT by batch
it works correctly
Zaidy036
2024-01-11 16:06:43 UTC
Permalink
Post by Zaidy036
Post by Herbert Kleebauer
Post by Zaidy036
Batch window closed and _NW-N.txt not generated.
Did you start the batch with a double click in explorer?
Then insert a pause at the end of the batch to see the
error message. Or better start the batch within an open
CMD window
If you started the batch within an opened CMD window
and the CMD window is closed when you execute the batch,
then you have a seriously problem. In this case simplify
the batch code until it doesn't crash and then add
code until you find the critical part of the code.
basically that is what I did and the addition of the cmd shown closes
the batch window but when run with an open cmd window and NOT by batch
it works correctly
I constructed the batch step by step using ECHO( & CMD /K before adding
a new step so I could check the results. The cmd in question closed the
window without results.
Herbert Kleebauer
2024-01-11 16:31:20 UTC
Permalink
Post by Zaidy036
Post by Herbert Kleebauer
Post by Zaidy036
Batch window closed and _NW-N.txt not generated.
Did you start the batch with a double click in explorer?
Then insert a pause at the end of the batch to see the
error message. Or better start the batch within an open
CMD window
If you started the batch within an opened CMD window
and the CMD window is closed when you execute the batch,
then you have a seriously problem. In this case simplify
the batch code until it doesn't crash and then add
code until you find the critical part of the code.
basically that is what I did and the addition of the cmd shown closes
the batch window but when run with an open cmd window and NOT by batch
it works correctly
You still didn't said how you start the batch.

Open a cmd window. CD to the directory where the batch
is stored. Name your batch test.bat so there is no name conflict
with a program with the same name and type test.bat to
execute the batch. Then you should see the error messages.
Zaidy036
2024-01-11 19:03:59 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
Post by Herbert Kleebauer
Post by Zaidy036
Batch window closed and _NW-N.txt not generated.
Did you start the batch with a double click in explorer?
Then insert a pause at the end of the batch to see the
error message. Or better start the batch within an open
CMD window
If you started the batch within an opened CMD window
and the CMD window is closed when you execute the batch,
then you have a seriously problem. In this case simplify
the batch code until it doesn't crash and then add
code until you find the critical part of the code.
basically that is what I did and the addition of the cmd shown closes
the batch window but when run with an open cmd window and NOT by batch
it works correctly
You still didn't said how you start the batch.
Open a cmd window. CD to the directory where the batch
is stored. Name your batch test.bat so there is no name conflict
with a program with the same name and type test.bat to
execute the batch. Then you should see the error messages.
When I must frequently test a batch as I develop it I add an icon to the
desktop. In this case it is set to run as administrator and produces the
same results as running from the actual file location.

For the tests I have my normal @ECHO OFF rem'd out so errors should show
and I have a PAUSE as the cmd before the one in question.

I ran three tests and it appears that {IF "%B"==" "} is the problem
because the first two tests crash. Note that the last shows %B is " " is
the value when the name does not exist.

FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (
IF "%B"==" " ECHO %%A >> F:\_NW-N.txt)

FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (IF
"%B"==" " ECHO "%%A" "%%B")

FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (ECHO
"%%A" "%%B")

If you are willing run the last cmd against your input file and see if
your "%B" is "" or " ". If "" could you add spaces where the names are
blank and retest?

The purpose of the batch is to collect Wi-Fi SSIDs that my system sees
and make a list of those I have passwords for. All works OK except when
an SSID has no name and the following cmds delete that SSID and replace
it with the same SSID with a dummy name. I tested by manually adding
names in _NW-B.txt and the present problem is all that remains to solve.
Herbert Kleebauer
2024-01-11 20:25:44 UTC
Permalink
Post by Zaidy036
When I must frequently test a batch as I develop it I add an icon to the
desktop. In this case it is set to run as administrator and produces the
same results as running from the actual file location.
But in this case you should really open a CMD window, CD to the directory
with the batch and start the batch with batchname.bat because then the
CMD window remains open after the batch has finished.
Post by Zaidy036
I ran three tests and it appears that {IF "%B"==" "} is the problem
because the first two tests crash.
I don't think your batch crashes, but it just ends without
finding an SSID without a name. Insert a

echo start batch > F:\_NW-N.txt

at the beginning of the batch and a

echo end batch >> F:\_NW-N.txt

at the end of the batch to make sure the batch doesn't crash.
Post by Zaidy036
Note that the last shows %B is " " is
the value when the name does not exist.
SSID 6 : ResidentsB
SSID 7 :

In my input file I have no space after the colon in "SSID 7 :".
If in your input file is a space, then you have to use
IF "%%B"==" "
Post by Zaidy036
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (
IF "%B"==" " ECHO %%A >> F:\_NW-N.txt)
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (IF
"%B"==" " ECHO "%%A" "%%B")
Is this line wrap done by your news reader or is it done this
way in your batch file (then you have to move the "IF" on the next line).
Post by Zaidy036
FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("F:\_NW-B.txt") DO (ECHO
"%%A" "%%B")
If you are willing run the last cmd against your input file and see if
your "%B" is "" or " ". If "" could you add spaces where the names are
blank and retest?
If I insert a space after "SSID 7 :" and use IF "%%B"==" " then the
batch also works. _NW-N.txt is created correctly.
Zaidy036
2024-01-11 21:37:18 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
Post by Herbert Kleebauer
Post by Zaidy036
Batch window closed and _NW-N.txt not generated.
Did you start the batch with a double click in explorer?
Then insert a pause at the end of the batch to see the
error message. Or better start the batch within an open
CMD window
If you started the batch within an opened CMD window
and the CMD window is closed when you execute the batch,
then you have a seriously problem. In this case simplify
the batch code until it doesn't crash and then add
code until you find the critical part of the code.
basically that is what I did and the addition of the cmd shown closes
the batch window but when run with an open cmd window and NOT by batch
it works correctly
You still didn't said how you start the batch.
Open a cmd window. CD to the directory where the batch
is stored. Name your batch test.bat so there is no name conflict
with a program with the same name and type test.bat to
execute the batch. Then you should see the error messages.
OK, learning something about how to see errors after a batch closure.

The reported error: ) was unexpected at this time.

But NOT really. After trying various different ( and ) arrangements
without success I did get it to work.

The fix was changing "IF %B==..." to "IF %%B==..."

But you had success using "IF %B==..." and maybe a different version of
Windows 10. Mine is Pro (10.0.19045 build 19045).
Herbert Kleebauer
2024-01-11 22:27:08 UTC
Permalink
Post by Zaidy036
The fix was changing "IF %B==..." to "IF %%B==..."
But you had success using "IF %B==..." and maybe a different version of
Windows 10. Mine is Pro (10.0.19045 build 19045).
In my first post here I said, you have to double % in a batch:

|| Is _NN a variable and %_NN% its content or is the % in
|| _%_NN%NW-N.txt part of the file name (you should never use
|| a % in a file name. In a batch file you have to double the %.


I posted the version which worked here. Why didn't you copy&past it?

|| ::@echo off
||
|| FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("D:\_NW-B.txt") DO (
|| IF "%%B"=="" ECHO %%A >> D:\_NW-N.txt)
Zaidy036
2024-01-12 00:20:54 UTC
Permalink
Post by Herbert Kleebauer
Post by Zaidy036
The fix was changing "IF %B==..." to "IF %%B==..."
But you had success using "IF %B==..." and maybe a different version of
Windows 10. Mine is Pro (10.0.19045 build 19045).
|| Is _NN a variable and %_NN% its content or is the % in
|| _%_NN%NW-N.txt part of the file name (you should never use
|| a % in a file name. In a batch file you have to double the %.
I posted the version which worked here. Why didn't you copy&past it?
||
|| FOR /F "USEBACKQ TOKENS=1,2 DELIMS=:" %%A IN ("D:\_NW-B.txt") DO (
|| IF "%%B"=="" ECHO %%A >> D:\_NW-N.txt)
I did but over all of the tests confused or lost some changes.

%%B==" " requires the space and %%B=="" worked for you because my post
of input did not make that clear.

Thanks for staying with me on this. Starting within an Admin-Cmd window
showed an error even if it was the wrong one and made me go further.
Kenny McCormack
2024-01-11 14:45:24 UTC
Permalink
In article <unot0d$30t1j$***@dont-email.me>,
Zaidy036 <***@air.isp.spam> wrote:
...
Post by Zaidy036
I guess it is time to SFC even though all my other programs and batches
run fine.
SFC???
--
I'll give him credit for one thing: He is (& will be) the most quotable President
ever. Books have been written about (GW) Bushisms, but Dubya's got nothing on Trump.

Tremendously wet - from the standpoint of water.
Loading...