use of bat in keyword search

0

Please if someone tells me how to make a change within a csv extension file, by a bat, I say if within the csv file I have written parts example:

Hlmm.dds 32 image.jpg

I want the bat to only place the text hlmm and change it to gfmm and that this inside the .csv file only changed that text without eliminating or modifying the rest of the written line. And keep your original extension .csv and stay like this:

gfmm.dds 32 image.jpg

Note: the csv extension is originally from free ofice (spreadsheet). but it also opens with text editors, I iterated that it retains its dividing cell character, which is the comma. By defauld

    
asked by Juan Carlos Villamizar Alvarez 24.12.2016 в 05:20
source

1 answer

1
@echo off
Setlocal EnableDelayedExpansion
if "%3" == "" goto ayuda
set cadorig=%1
set cadorig=%cadorig:"=%
set cadsust=%2
set cadsust=%cadsust:"=%
for %%f in (%3) do (call :cambiar %%f)
goto fin
:cambiar
set archivo=%1
for /f "tokens=* delims=" %%i in (%archivo%) do (set ANT=%%i&echo   !ANT:%cadorig%=%cadsust%! >>kk_temp.txt)
copy /y kk_temp.txt %archivo%
del /q kk_temp.txt
goto :EOF
:Ayuda
Echo Reemplaza una cadena por otra en el contenido de archivos (con comodines)
echo Utiliza un archivo temporal kk_temp.txt que no debe existir previamente
echo Formato: %0 cadorig cadsust archivos
echo Si las cadenas contienen espacios deben escribirse entrecomilladas
echo No funciona si la cadena original contiene un "="
Echo Ejemplo:
echo %0 de DE *.txt
:Fin

USE

  

replace.bat Hlmm "gfmm" C: \ test \ myfile.csv

    
answered by 26.12.2016 / 19:10
source