Replacing characters in a text file with a batch f

2020-04-05 08:11发布

Is there a way to replace some characters in a text file with a batch file?

I didn't find any command to do that.

标签: batch-file
7条回答
贼婆χ
2楼-- · 2020-04-05 08:19

you can install unxutils and then do

sed "s/WORD_FROM/WORD_TO/" file_name > changed.file.name

to change words or

cat file|tr "a" "b"  > changed.file.name

to change characters

查看更多
Viruses.
3楼-- · 2020-04-05 08:20

You can use DOS port of Unix command line utility "tr".

A free DOS port can be found here, one of the ones I like (there are many different ones) are "UXUTL — Comprehensive collection of command line Unix utilities for DOS."

The benefit is that you get a WHOLE BUNCh of incredibly useful commands, not just tr.

查看更多
叛逆
4楼-- · 2020-04-05 08:21

You have to use WIN32 SED and see the official gnu sed page for explanation. It is really powerful :

> sed "s/WORD_FROM/WORD_TO/" file_name > changed.file.name
查看更多
萌系小妹纸
5楼-- · 2020-04-05 08:30

You can search for a command line program like GREP you can call from a batch that will take a replace string and a file and do the swap for you.

查看更多
够拽才男人
6楼-- · 2020-04-05 08:37

Use sed or nothing:

sed -i 's/FROM/TO/g' filename.txt

sed can be download here, for various platforms.

查看更多
等我变得足够好
7楼-- · 2020-04-05 08:41

Even though this question is quite old, future reader may be interested to know that if you want a small exe with no dependencies for just replacing text I recommend using FART.

查看更多
登录 后发表回答