- 2011-10-27 (木) 16:03
- Windows
小ネタ。Fortran の複素数を出力したファイルから ( と ) を除去するバッチファイル。( の代わりに ,(カンマ) に置換したりとか。Windows の cmd.exe のみで実行できるようにしてみました。
@echo off : ファイル名指定が無ければ終了 if %1=="" goto end : 入力ファイルを作業用ファイルにコピーしてから set fname=%1 copy %fname% orig >nul : 入力ファイルを空にする type nul >%fname% : 作業用ファイルから1行ずつ読み込んで置換処理 for /f "delims=" %%a in ( orig ) do ( set line=%%a call :sub ) : 作業用ファイルを削除して終了 del orig goto end :sub : 読み込んだ行から ) は削除。 ( は , に置換。 set tmp=%line% set tmp=%tmp:(=,% set tmp=%tmp:)=% echo %tmp%>>%fname% goto :EOF :end
リダイレクト記号なんかはダメっぽいけど、とりあえずちょろっとした処理には使えそう。
以下の関連(しているかもしれない)記事もどうぞ!
- (関連した投稿はありません)
コメント:0
トラックバック:0
- このエントリーのトラックバックURL
- http://digitalbox.jp/happy-go-lucky-computing/windows/replace-strings-in-batch-process-on-windows/trackback/
- Listed below are links to weblogs that reference
- 小ネタ: Windows のバッチファイルで文字列置換 from digitalbox
