Loading ...
Sorry, an error occurred while loading the content.

Re: [BATCH WORLD] parse and filter a txt file

Expand Messages
  • John O'Regan
    Dear Adhijat, Please review the following: - - adhijat.cmd - - @echo off & setlocal enableextensions set /a keycount=0,kc=0 type nul matches.txt for /f
    Message 1 of 6 , Aug 31, 2012
    View Source
    • 0 Attachment
      Dear Adhijat,

      Please review the following:

      - - adhijat.cmd - -

      @echo off & setlocal enableextensions
      set /a keycount=0,kc=0
      type nul > matches.txt

      for /f "delims=" %%a in (id.txt) do set "tail=%%a"

      :chomp
      for /f "tokens=1* delims=," %%b in ("%tail%") do (
      set /a keycount+=1
      call set "key%%keycount%%=%%b"
      set "tail=%%c"
      if "%tail%"=="" goto keys
      goto chomp)

      :keys
      set /a kc+=1
      call set "key=%%key%kc%%%"

      for /f "delims=" %%d in (data.txt) ^
      do for /f "tokens=5 delims=," %%e in ("%%d") ^
      do if /i "%key%"=="%%e" >>matches.txt echo(%%d

      if %kc% lss %keycount% goto keys

      endlocal & exit /b 0

      - - end-of-file - -

      I made some assumptions:

      * no spaces or "poison characters" in filenames
      * id.txt is only one line long
      * id.txt contains at least one key value
      * all the keys in id.txt are different
      * IDs and data are separated by commas with no whitespace around them
      * IDs and data do not contain any spaces or "poison characters"
      * match is case insensitive
      * all filenames are hard-coded into the program

      Even with all these provisos, the program generated the correct
      results using the sample data you provided.

      HTH!
      John
    • mail_abhijat
      Hi John, I haven t got around it yet. I was getting some error but had to move to something more business demanding. Nevertheless, thanks very much. I will
      Message 2 of 6 , Sep 26, 2012
      View Source
      • 0 Attachment
        Hi John,
        I haven't got around it yet. I was getting some error but had to move to something more business demanding.

        Nevertheless, thanks very much.

        I will keep you posted on my results.

        Kind Regards,
        Abhijat.

        --- In batchworld@yahoogroups.com, "John O'Regan" <john.a.oregan@...> wrote:
        >
        > Dear Adhijat,
        >
        > Please review the following:
        >
        > - - adhijat.cmd - -
        >
        > @echo off & setlocal enableextensions
        > set /a keycount=0,kc=0
        > type nul > matches.txt
        >
        > for /f "delims=" %%a in (id.txt) do set "tail=%%a"
        >
        > :chomp
        > for /f "tokens=1* delims=," %%b in ("%tail%") do (
        > set /a keycount+=1
        > call set "key%%keycount%%=%%b"
        > set "tail=%%c"
        > if "%tail%"=="" goto keys
        > goto chomp)
        >
        > :keys
        > set /a kc+=1
        > call set "key=%%key%kc%%%"
        >
        > for /f "delims=" %%d in (data.txt) ^
        > do for /f "tokens=5 delims=," %%e in ("%%d") ^
        > do if /i "%key%"=="%%e" >>matches.txt echo(%%d
        >
        > if %kc% lss %keycount% goto keys
        >
        > endlocal & exit /b 0
        >
        > - - end-of-file - -
        >
        > I made some assumptions:
        >
        > * no spaces or "poison characters" in filenames
        > * id.txt is only one line long
        > * id.txt contains at least one key value
        > * all the keys in id.txt are different
        > * IDs and data are separated by commas with no whitespace around them
        > * IDs and data do not contain any spaces or "poison characters"
        > * match is case insensitive
        > * all filenames are hard-coded into the program
        >
        > Even with all these provisos, the program generated the correct
        > results using the sample data you provided.
        >
        > HTH!
        > John
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.