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

Delete text in .txt files with dos

Reply to Message Icon

Original Message
Name: bulleke
Date: April 8, 2005 at 05:30:20 Pacific
Subject: Delete text in .txt files with dos
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


Report Offensive Message For Removal


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

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.


Report Offensive Follow Up For Removal

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

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.


Report Offensive Follow Up For Removal

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

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.


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Delete text in .txt files with dos

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge