NeoVe
NeoVe

Reputation: 3897

Add commas to txt file from batch script in Windows

I have this format on a .txt file:

"Rosina Merola ([email protected])" <[email protected]> 
"Sabina Morales ([email protected])" <[email protected]> 
"Sorella Blanco ([email protected])" <[email protected]> 
"Eduardo Schmilinsky Leal" <[email protected]>
"Elba Rodríguez" <[email protected]>
Ernesto Ramirez <[email protected]>

Some of the names have ""and a few don't, as you can see in this example.

However, i need to add a comma ',' after each name and before the email line <>

I thought that first adding the "" to every name, it could be easier then to add the commas, i have this code:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (nombresemails.txt) do (
echo "%%a", >> nombresemailscomillas.txt
)

It works but it adds the "" in this format:

"Adam Podlinski <[email protected]> ", 
"Adam Podlinski 2 <[email protected]>", 
""Aldo Gonzalez " <[email protected]>", 
""Alejandr Rubin" <[email protected]>", 
""Alfredo Huguett " <[email protected]>", 
""[email protected]" <[email protected]>", 

No matter what are the characters it just adds the "" even if they already have it, and besides, it adds them to all the line, i just need to add them to every name, leaving the emails inside the <> without the "".

Anyway, this is just an approach i thought it could work, basically i just need to add a comma after every name and before the emails cointained in <>

there is actually some way achieve this on batch code?

Thanks in advance!

Upvotes: 4

Views: 1863

Answers (1)

foxidrive
foxidrive

Reputation: 41224

This works here:

@echo off
setLocal EnableDelayedExpansion
   for /f "delims=" %%a in (nombresemails.txt) do (
      set "line=%%a"
      set "line=!line: <=,<!"
        >>nombresemailscomillas.txt echo !line!
)

Upvotes: 3

Related Questions