I have a text file that contains gmail contacts, after each address there's the name of the email address owner example : John(at)gmail(dot)com:John and some other emails like this : John(at)gmail(dot)com;John each address is in a new line, I want to delete all names and keep just the addresses, so I don't have to do it manually each time. how can I do this in batch script. I want to delete everything after ":" or ";" in every line. Thanks
Asked
Active
Viewed 120 times
0
-
There's no easy way to do search and replace using batch commands directly, there are many third party tools made to help, but actually I prefer using VBSCRIPT directly in windows command prompt, check this question: https://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file – Babak Jun 17 '19 at 20:51
-
4@Babak - Not only does batch have search and replace, but that doesn't even come into play here since this can be handled with a simple `for /f` loop using `:` as a delimiter. – SomethingDark Jun 17 '19 at 20:58
-
It is interesting, so I guess you have an answer for our friend here, and I'll learn something new as well :) – Babak Jun 17 '19 at 21:02
-
1this is well explained in the [documentation](https://ss64.com/nt/for_f.html) – Stephan Jun 17 '19 at 21:07
1 Answers
2
It's a simple one-liner:
(FOR /f "delims=:;" %%a IN (filename1) DO ECHO %%a)>filename2
where filename* are your filenames and >
should be replaced by >>
to append to filename2 rather than creating filename2 anew.

Magoo
- 77,302
- 8
- 62
- 84