怎樣用DOS命令替換文本裡的某段字元

來源:互聯網
上載者:User
事情是這樣的,我一個txt檔案,我想把裡面的所有3.6改成6*3
請問有什麼方法嗎?謝謝
我來幫他解答精彩回答 2008-12-24 00:51
@echo off
setlocal enabledelayedexpansion
set file=
set /p file= 請輸入要操作的檔案名稱(包括副檔名):
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
set replaced=
set /p replaced= 請輸入即將被替換的內容:
set all=
set /p all= 請輸入替換字串:
for /f "delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>"%file%"_tmp.txt
)
copy "%file%" "%file%"_bak.txt >nul 2>nul
move "%file%"_tmp.txt "%file%"
start "" "%file%"
5|評論

求助知友

BB石俊傑 | 當前分類:17 級 排名:18

擅長Windows:21 級 排名:597

提問者對回答的評價:
謝謝了,不過能不能改成直接替換原檔案而不另外產生新檔案
按預設排序|按時間排序

其他回答 共2條 2008-12-25 11:07qivsran| 當前分類:11 級 排名:274
@echo off&&setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (我一個txt檔案.txt) do (
set var=%%i
set "var=!var:3.6=6*3!"
echo !var!>>我一個txt檔案_fin.txt
)

http://zhidao.baidu.com/question/80037354.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.