Replace text in a file using Batch script

Victor Leung
Jul 31, 2018 · 2 min read
something
id: 4
something else
id: 64
next one
id: 231
another one
id: 34
something
id:
somthing else
id:
next on
id:
another one
id:
@echo off
(for /f "tokens=1* delims=:" %%a in (temp.yaml) do (
if "%%b"=="" (echo %%a) else (
echo %%a|find " id" >null&& echo %%a: ||echo %%a: %%b
)
))>result.yaml

Victor Leung

Written by

I’m a keen traveler to see every country in the world, passionate about cutting edge technologies.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade