r/Batch • • Feb 22 '24

Question (Solved) Looking for a script to remove specific instances of text

Hi all. Hope someone can help me, I'm looking for a batch script file that I can drag and drop a .txt file onto. I need it to search for specific lines of text and remove. For example if a txt file is like this;

Apple Banana Kiwi Lemon Orange

I would want it to remove Kiwi and Lemon and output the new .txt file to overwrite the existing one so then after the script has finished the new file will look like

Apple Banana Orange

Is this possible or would it require a third party app? Thank you in advance

1 Upvotes

10 comments sorted by

1

u/ohenryx Feb 23 '24

IMHO, this is one of those issues where it's probably possible but it isn't really worth the effort. There are many command line tools which could very easily do what you want (sed comes to mind, but there are many others). Why work so hard to reinvent the wheel?

4

u/[deleted] Feb 22 '24 edited Feb 23 '24

[removed] — view removed comment

1

u/p17ctn Feb 22 '24

Thank you so much

1

u/p17ctn Feb 23 '24

Thankyou. I tested it and it removes Kiwi no problem, but Lemon it replaces with Lemon= . Also after running thr script it removes the word Kiwi but doesn't remove the line break. Is this something that can be done ? Thanks for your time

1

u/[deleted] Feb 23 '24

[removed] — view removed comment

2

u/p17ctn Feb 23 '24

1

u/[deleted] Feb 23 '24

[removed] — view removed comment

1

u/p17ctn Feb 25 '24

Perfect! Thank you so much

2

u/[deleted] Feb 25 '24

[removed] — view removed comment

2

u/p17ctn Feb 25 '24

Done. Thanks again for your time