Home Count total words from text file serperated by "," (comma) in batch script

# Count total words from text file serperated by "," (comma) in batch script

Kaushal Dave
1#
Kaushal Dave Published in 2017-09-12 13:02:44Z
 I have a comma d eliminated text file (names.txt) in which there is a string for ex Mike,Joe,Kelly. I need to get total count of strings like : total name : 3 and store this result in a variable and call it further in my batch script. I googled a lot but not getting proper code. It would be really great if I can get an answer from this expert group. Thanks a lot in advance.
Quanmao
2#
 A simple way, just 1 command line: ( name count is just the return value %ERRORLEVEL% ) msr -p your-file.txt -t "," -o "\n" -PAC | msr -t "\w+" Store to a variable: Name count ? set /a NameCount=%ERRORLEVEL% Full string ? set "ResultText=Total name : %ERRORLEVEL%" Additionally, if you want to hide output of the command, redirect output to nothing by >nul : msr -p your-file.txt -t "," -o "\n" -PAC | msr -t "\w+" >nul msr.exe / msr-Win32.exe is a single portable exe tool for file processing with cross platform versions. see tools directory in my open project https://github.com/qualiu/msr . You can also see: https://qualiu.github.io/msr/usage-by-running/msr-Windows.html
 When I understand correctly, your textfile has only one line. @echo off