Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Divide a string from a .CSV file into command-line arguments

Aug
2,799
144
This is a demonstration script of how to divide a string into command-line arguments,
using the PARSEARGS command from the TextUtils plugin.

Code:
@SETLOCAL
@ECHO OFF
:: Demonstration of the parseargs command,
::   from the TextUtils plugin.
:: https://charlesdye.net/plugins/textutils.html#parseargs

if isdir r:\temp set temp=r:\temp

do x in e:\downloads\holdings-report*.csv (set LastFile=%x)

set MaxLines=%@lines[%LastFile]
set MaxLines=%@eval[%MaxLines-2]

:: The parseargs command is in the TextUtils plugin
if not plugin TextUtils plugin /l e:\utils\TextUtils.dll

:: Disable multiple commands, conditional commands, and piping
:: One company has an ampersand in their name
setdos /X-5

:: Example ticker
set theTicker=DOL

:: Line 0 are the Headings
do kount=1 to %MaxLines
  :: Divide a string into command-line arguments.
  :: The resulting arguments are stored in an array.
  parseargs /Q /A:holdings /f:2 !%@line[%LastFile,%kount]
 
  set qty=%HOLDINGS[9]
  set Symbol=%HOLDINGS[4]
  set Market_Price=%HOLDINGS[11]
  set Book_Value=%HOLDINGS[15]
  set Market_Value=%HOLDINGS[17]
  set UnRealized=%HOLDINGS[19]
 
  iff %Symbol eq %theTicker then
    echo As Of       : %@filedate[%LastFile]
    echo Symbol      : %Symbol
    echo Qty         : %Qty
    echo Market Price: %@right[7,       %@formatn[4.2,%Market_Price]]
    echo Book Value  : %@right[7,       %@formatn[4.2,%Book_Value]]
    echo UnRealized  : %@right[7,       %@formatn[4.2,%UnRealized]]
    echo Market Value: %@right[7,       %@formatn[4.2,%Market_Value]]
  endiff
enddo
setdos /X+5
ENDLOCAL

Great for working with .CSV files.

Joe
 
Back
Top