2014-11-03 106 views
0

我有一個關於使用'repl'批處理命令的問題,特別是它的替換參數。repl.bat:在替換參數中使用正則表達式

花費時間閱讀文檔...: - )...和一些測試,看起來正則表達式不能用在replace參數中。

「type file.txt | repl」Jacob還活着。他活着。\ n「」貝蒂過日子。\ n請進貝蒂。「M> file.txt.new」

這將使用字符'。'來進行文字替換。 &'\ n'而不是插入新行。這是真的正則表達式不能用在repl.bat的[replace]參數中嗎?如果沒有,你知道一種方法來實現這種行爲?提前致謝!

+0

由於repl.bat不來標準與Windows,你應該提供一個鏈接以便不熟悉它的人可以提供幫助。 – SomethingDark 2014-11-04 01:57:26

+0

我的歉意。這裏是repl.bat [link](http://www.dostips.com/forum/viewtopic.php?f=3&t=3855}和最早的StackOverflow文章[link](https:// stackoverflow。 com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir/16735079#16735079)from @dbenham。 – rwbyrd 2014-11-04 14:28:44

回答

0

repl.bat /?信息中提取

M - Multi-line mode. The entire contents of stdin is read and 
     processed in one pass instead of line by line, thus enabling 
     search for \n. This also enables preservation of the original 
     line terminators. If the M option is not present, then every 
     printed line is termiated with carriage return and line feed. 
     The M option is incompatible with the A option unless the S 
     option is also present. 

    X - Enables extended substitution pattern syntax with support 
     for the following escape sequences within the Replace string: 

     \\  - Backslash 
     \b  - Backspace 
     \f  - Formfeed 
     \n  - Newline 
     \q  - Quote 
     \r  - Carriage Return 
     \t  - Horizontal Tab 
     \v  - Vertical Tab 
     \xnn - Extended ASCII byte code expressed as 2 hex digits 
     \unnnn - Unicode character expressed as 4 hex digits 

所以,你repl命令選項應該MX而不是僅僅M

+0

啊,我是在正確的軌道上,我已經嘗試過了,但是在選項中分開了M和X,導致了它的悲傷,這看起來效果很好! – rwbyrd 2014-11-04 14:31:21