batch script to find the occurrence of a string

July 9, 2012 at 04:04:37
Specs: Windows XP
Is it possible to write a batch script to find the occurrence of a string (‘”’) in multiple files in a directory after the immediate fourth occurrence of another string (‘|’)?
The whole requirement is like this.
There are some pipe (‘|’) delimited files in a directory which I need to process.
After the fourth occurrence of the delimiter (‘|’) in each row, if there is a double quote gets open then it need to get closed before the last pipe delimiter starts.
If there are more that two double quotes are there then we need to keep the first al last positional quotes, and rest we need to remove,
And if there are no quotes present then no modification is required for the record.

See More: batch script to find the occurrence of a string

July 9, 2012 at 05:28:26
Post the file. If it's large, post it to, then link it here.


Report •

December 10, 2012 at 09:33:24
if a file has a record like this

i need the output as the number of times the | symbol has repeated i.e 4 here

Report •

December 10, 2012 at 18:41:52
@mreddy19: OP has long ago moved on i figure. If he is indeed still waiting (very patiently, i might add), then he probably would have reposted by now or at least generated some additional content. Too bad, it looked like a fun challenge! ;-)

Report •

Related Solutions

December 12, 2012 at 03:34:24
can any one anwser this?

Report •

December 12, 2012 at 10:25:26
This seems to work, does not count null fields:

@echo off & setlocal enabledelayedexpansion
set #=0
for /f "tokens=*" %%i in (
) do (
set line=%%i
set line=!line:^|=,!$
for %%a in (!line!) do set /a #+=1
set /a #-=1
echo !#! 
goto :eof

I was playing with this string:

It doesn't count the null field, anyone got a way to do it? My script returns 5, should be 6.


Report •

December 12, 2012 at 21:17:20
@echo off & setlocal
for /f "tokens=*" %%a in (pipes) do (
call :count "%%a"
goto :eof

set aa=0
set xx=%1
set zz=%1
rem :: get raw /original length of line
call :len
set len1=%aa%

:delete the pipe (or whatever)
set xx=%zz:|=%
:: confirm / debug
:: echo new xx: %xx%

set aa=0
rem :: get new length (after deletions)
call :len
set /a dif=len1-aa
echo no. of pipes: %dif%
goto :eof

set /a aa+=1
set xx="%xx:~2%
if %xx% neq "" goto :len
::==== end batch
This only counts. vbscript would be way better suited for serious use.

Report •

Ask Question