- 1 year ago
Split txt file delimited by space or comma and concatenate a suffix in a .bat
Sure, you can split a text file delimited by space or comma and then concatenate a suffix to each value using a batch script. Here's an example batch script to achieve this:
batch@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
set "suffix=_suffix"
(for /f "tokens=1* delims=, " %%a in (%inputFile%) do (
echo %%a%suffix%%%b
)) > %outputFile%
echo Done!
This script assumes you have an input.txt
file containing the data you want to process. It will create an output.txt
file with the modified values by appending the _suffix
to each value. You can customize the file names and the suffix as needed.
Remember to replace input.txt
and output.txt
with the actual names of your input and output files.
This script uses a for /f
loop to read each line of the input file, split the values using spaces or commas as delimiters, and then concatenate the suffix to the first value. The modified lines are then redirected to the output file.
Just save the script in a .bat
file and run it in the same directory as your input file. Make sure to backup your data before running any script that modifies files.