'batch file will not read the entire csv file i have

I have a csv file with around 9500 rows and around 60 columns (if opened up in excel). I am trying to have the program read the 1st value in the row and output it to a txt file. Right now I have the code giving me the first and last value it reads:

@echo off
setlocal enableextensions enabledelayedexpansion


set "input_file=file.csv"

type nul > file2.txt

set "first="
set "last="

for /f "skip=1 tokens=* delims=," %%i in (!input_file!) do (
    set line="%%i"
    for /f "tokens=1 delims=," %%b in ("!line:,="^,"!") do (
    if not defined first set "first=%%~b"
    set "last=%%~b"
)
)

echo %first% >>file2.txt
echo %last% >>file2.txt

I have it to change every , to "," because I have some blank values. For some reason the last value it reads is actually the 2985th value in the 9500 rows. In reality it is only reading 2984 rows total and then stopping. Is this because of some limitation on the csv file/batch reading abilities or is my code wrong? Any help would be appreciated.

EDIT: My end goal is to take this csv file, read the 31st column, if it is an O then output the entire line into the txt/csv file, if it is a C then skip it. Essentially I am trying to sort out all of the rows that have an O in the 31st column so that eventually I can send that txt file through email to someone. This is just the beginning because I am a noob at writing code.

EDIT: another edit, the csv file is updated daily and now it only goes down to like row 1040 out of 9500 rows. It seems to change what the last value is everyday.

EDIT: just realized i dont actually have it changing every , to "," it just encircles every new line with "". is changing every , to "," something i should try to figure out or does anyone have another idea?

EDIT: Ok so figured out how to output the lines with an O but the script only reads 203 lines now and outputs the only 4 O's in those 203 lines, like bruhh. Here is the final code that I have:

@echo off
setlocal enabledelayedexpansion


set "input_file=file.csv"

type nul > file2.txt

set "status="

for /f "skip=1 tokens=* delims=," %%i in (!input_file!) do (
    set line=%%i
    for /f "tokens=1 delims=," %%b in ("!line:,=^,!") do (
    set status=%%b
    if "!status!" == "O^" (
    echo !line! >> file2.txt
)
)
)


Solution 1:[1]

If you just copied/pasted the command on the Flutter documentation, this one, keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload, then the alias would be upload and not key.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Richard Heap