Computing.Net > Forums > Programming > Delete text in .txt files with dos

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete text in .txt files with dos

Reply to Message Icon

Name: bulleke
Date: April 8, 2005 at 05:30:20 Pacific
OS: Windows XP
CPU/Ram: 128 MB
Comment:

How can I delete "sheep" in a text file and put "horse" in it's place
ps: sheep is always the first word in every line, so you could delete the word sheep and put horse in the beginning of evey line



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 8, 2005 at 06:47:38 Pacific
Reply:

Most word processors have a 'search & replace' capability.

Are you looking for a 'program' solution?


M2


If at first you don't succeed, you're about average.


0

Response Number 2
Name: Mechanix2Go
Date: April 8, 2005 at 06:50:03 Pacific
Reply:

ooops,

I just re-read your post. You want to do it in DOS.

No straightforward way that I know if in DOS. It will take a 3rd party utility.

M2


If at first you don't succeed, you're about average.


0

Response Number 3
Name: IVO
Date: April 8, 2005 at 07:20:23 Pacific
Reply:

If "in DOS" means Win XP/2K prompt, as I suspect, that can be achieved by For /F statement. Something as

For /F "tokens=1*" %%A in (Text_File) Do (
Echo horse %%B >> New_Text_File)
Move New_Text_File Text_File /Y

but you get a solution only if you can understand it.


0

Response Number 4
Name: FishMonger
Date: April 8, 2005 at 08:52:07 Pacific
Reply:

It would be a lot more efficient if you use any one of a number of scripting languages other than a DOS batch file. My personal preference would be Perl. This Perl command will do an inline edit of the file and create a backup copy of the original file.

Perl –pi.bak -e “s/^sheep/horse/;” file.txt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Delete text in .txt files with dos

manipulate/delete text in bat file? www.computing.net/answers/programming/manipulatedelete-text-in-bat-file/15153.html

del text in txt file except dir www.computing.net/answers/programming/del-text-in-txt-file-except-dir/17223.html

add or replace text in .txt file www.computing.net/answers/programming/add-or-replace-text-in-txt-file/18121.html