※ Elliott Pattern Helper Add In
▶ Counting lines of a data file
@echo off
echo.
set WF_DATA=sample.dat
set /a nlines=0
for /f %%a in ('type "%WF_DATA%"^| find "" /v /c') do set /a nlines=%%a
echo The number of lines of %WF_DATA% is %nlines%
▶ Counting columns of a data file
    (※ gawk for windows must be pre-installed)
 @echo off
echo.
set WF_DATA=sample.dat
echo.
set WF_DATA=sample.dat
 for /f %%a in ('gawk ^
 "BEGIN {^
         FS = """ """^
 }^
 END {^
         print NF^
 }^
 " %WF_DATA%') do set N=%%a
 echo The number of columns is %N%
▶ Finding Min / Max of a column in a data file
    (※ gawk for windows must be pre-installed)
 @echo off
echo.
echo.
 set WF_ANFIS=anfis.dat
 for /f "tokens=1-2" %%a in ('gawk -f bound.awk %WF_ANFIS%') do (
 set XLOW=%%a
 set XHIGH=%%b
 )
 echo XLOW %XLOW%
 echo XHIGH %XHIGH%
 (※ bound.awk is as follows)
 C:\Users\drstones\Documents\Visual Studio 2012\Projects\anfis_wf>type bound.awk
 BEGIN {
         first_x_val = 99999999999
         last_x_val = -99999999999
 }
 {
         if ($1 < first_x_val) {
                 first_x_val = $1;
         }
         if ($1 > last_x_val) {
                 last_x_val = $1;
         }
 }
 END {
         print first_x_val " " last_x_val;
 }
▶ Incrementing a variable in for /f loop
 @echo off
echo.
echo.
 set WF_ANFIS=anfis.dat
 set cnt=0
 for /f %%b in ('gawk -f bound1.awk %WF_ANFIS%') do (
 if !cnt! == 0 (
 set XLOW=%%b
 ) else (
 set XHIGH=%%b
 )
 set /a cnt=cnt+1
 )
 echo XLOW %XLOW%
 echo XHIGH %XHIGH%
 (※ bound1.awk is as follows)
 C:\Users\drstones\Documents\Visual Studio 2012\Projects\anfis_wf>type bound1.awk
 BEGIN {
         first_x_val = 99999999999
         last_x_val = -99999999999
 }
 {
         if ($1 < first_x_val) {
                 first_x_val = $1;
         }
         if ($1 > last_x_val) {
                 last_x_val = $1;
         }
 }
 END {
         print first_x_val;
         print last_x_val;
 }
 
 
댓글 없음:
댓글 쓰기