Find String in text file using batch script -


i loop on every line of .txt file within batch script, , every string in it.

my file

'string number 1' 'string number 2' 'string number 3' 'string number 11' 'string string' //... 

and know how every strings surrounded simple quotes.

i hope i'm clear enough.

thanks !

@echo off setlocal enabledelayedexpansion  set "sourcedir=u:\sourcedir" set "destdir=u:\destdir" set "outfile=%destdir%\outfile.txt" set "filename1=%sourcedir%\q35266036.txt" ( /f "usebackqdelims=" %%a in ("%filename1%") (  set "line=%%a"  set "line=!line:'="!"  %%w in (!line!) echo '%%~w' ) )>"%outfile%"  goto :eof 

you need change settings of sourcedir , destdir suit circumstances.

i used file named q35266036.txt containing data testing.

produces file defined %outfile%

simply, read each file %%a put in line strng-manipulation.

replace each ' "

process space-separated list of double-quotes strings.

remove quotes , replace single-quotes (if required)


revision save first 2 items

@echo off setlocal enabledelayedexpansion  set "sourcedir=u:\sourcedir" set "destdir=u:\destdir" set "outfile=%destdir%\outfile.txt" set "filename1=%sourcedir%\q35266036.txt" set "item1=" set "item2=" ( /f "usebackqdelims=" %%a in ("%filename1%") (  set "line=%%a"  set "line=!line:'="!"  %%w in (!line!) (   echo '%%~w'   if defined item1 if not defined item2 set "item2=%%~w"   if not defined item1 set "item1=%%~w"  ) ) )>"%outfile%"  echo item1=%item1% echo item2=%item2%  goto :eof 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -