how to find the words which are between FS or WFS and "{" in a file and insert timestamp after the found word and before "{".
Example:
FS mmmmmmmmmm {
After running the script:
FS mmmmmmmmmm_timestamp {
how to find the words which are between FS or WFS and "{" in a file and insert timestamp after the found word and before "{".
Example:
FS mmmmmmmmmm {
After running the script:
FS mmmmmmmmmm_timestamp {
Very simple using REPL.BAT - a hybrid JScript/batch utility that performs a regular expression search/replace on stdin and writes the result to stdout. REPL.BAT is pure script that will run on any modern Windows machine from XP onward. This will also be much faster than any pure batch solution.
type "file.txt" | repl "(\bW?FS [^{]*[^{ ])( *{)" "$1_timestamp$2" >"file.txt.new"
move /y "file.txt.new" "file.txt"
You don't specify, but perhaps you want a timestamp value instead of the string literal "timestamp". You can use any of the methods at How to get current datetime on Windows command line, in a suitable format for using in a filename? to get the current timestamp, or for the ultimate in ease of use and flexibility, you could use my getTimestamp.bat utility - another hybrid JScript/batch utility.
You don't say what format the timestamp should have, nor what degree of precision. I'll assume you want a format that is suitable for a file name - YYYY-MM-DD_hh-mm-ss
.
@echo off
setlocal
call getTimetamp -f "{YYYY}-{MM}-{DD}_{HH}-{NN}-{SS}" -r ts
type "file.txt" | repl "(\bW?FS [^{]*[^{ ])( *{)" "$1_%ts%$2" >"file.txt.new"
move /y "file.txt.new" "file.txt"