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

Report •

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

Tony


Report •

#2
December 10, 2012 at 09:33:24
if a file has a record like this
a|b|c|d|e

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


Report •

#3
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

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

Report •

#5
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 (
test.txt
) 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:
a|b|c|d|e||

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

Tony


Report •

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

:count
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

:len
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