【发布时间】:2018-10-30 21:59:39
【问题描述】:
我想替换两个字符串[REPORT] 和[TAGS] 之间的行。文件看起来像这样
Many lines many lines they remain the same [REPORT] some text some more text412 [TAGS] text that I Want to stay the same!!!
我在cygwin 中使用了sed:
sed -e '/[REPORT]/,/[TAGS]/c\[REPORT]\nmy text goes here\nAnd a new line down here\n[TAGS]' minput.txt > moutput.txt
这给了我这个:
Many lines many lines they remain the same [REPORT] my text goes here And a new line down here [TAGS] text that I Want to stay the same!!!
当我这样做并在记事本中打开输出文件时,它不会显示新行。我认为这是因为格式问题,一个简单的Dos2Unix 应该可以解决问题。
但正因为如此,也主要是因为并非我的所有同事都可以访问cygwin 我想知道cmd 是否有办法做到这一点(或者Powershell 如果没有办法做一批)。
最终,我想在多个文件上运行此命令,并将其中的这一部分(在上述两个单词之间)更改为我提供的文本。
【问题讨论】:
标签: cygwin cmd powershell cmd cygwin text-processing