StockFetcher Forums · General Discussion · Collator batch script<< >>Post Follow-up
fotchstecker
310 posts
msg #161906
Ignore fotchstecker
modified
7/23/2025 2:46:20 PM

Here's a batch script that will let you collate the symbols (in A1) for a bunch of downloaded symbol.csvs.
Screenshot below.

1. save it as batch file. name it whatever.
2. put it in a folder with all of your downloaded symbols files. This should be a clean folder with just the script and files.
3. double-click it.
4. it will ouput a deduped text file listing all symbols in all of your original files.


@echo off
setlocal enabledelayedexpansion

:: Define the temporary file to store all symbols (which will become our initial raw output)
set "rawOutputFile=all_symbols_raw.txt"

:: Define the final deduplicated output file
set "finalOutputFile=collated_symbols_deduplicated.txt"

:: Clean up previous runs
if exist "%rawOutputFile%" del "%rawOutputFile%"
if exist "%finalOutputFile%" del "%finalOutputFile%"

echo Starting collation...

:: Loop through all CSV files in the current directory
for %%f in (*.csv) do (
:: Skip any potential output files if they exist (though this setup avoids conflict)
if not "%%f"=="%rawOutputFile%" if not "%%f"=="%finalOutputFile%" (
echo.
echo Processing file: %%f
:: Read each line of the CSV file, skipping the first line (header)
for /f "skip=1 tokens=1* delims=," %%a in ('type "%%f"') do (
:: Extract the first column (symbol) and trim any whitespace
set "currentSymbol=%%a"
:: Remove leading/trailing spaces (if any exist)
for /f "tokens=*" %%x in ("!currentSymbol!") do set "trimmedSymbol=%%x"
if not "!trimmedSymbol!"=="" (
echo Adding symbol: !trimmedSymbol!
echo !trimmedSymbol!>>"%rawOutputFile%"
)
)
)
)

echo.
echo Finished processing all source CSV files.
echo.
echo Now deduplicating and writing to final output text file...

:: Deduplicate the symbols from the raw output file and write to the final deduplicated output file
if exist "%rawOutputFile%" (
:: Sort the raw symbols and get ONLY unique ones.
sort /unique "%rawOutputFile%" > "%finalOutputFile%"

echo Total raw symbols found:
find /c /v "" "%rawOutputFile%"
echo Total unique symbols written:
find /c /v "" "%finalOutputFile%"

:: Clean up the temporary raw file
del "%rawOutputFile%"
) else (
echo No symbols were found in any files to process.
)

echo.
echo Collation complete. Deduplicated symbols written to "%finalOutputFile%".
pause







StockFetcher Forums · General Discussion · Collator batch script<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2022 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.