Board logo

标题: (已结)怎样在dos命令行下删除指定的文件中的字符 [打印本页]

作者: dvliu     时间: 2005-7-23 12:12    标题: (已结)怎样在dos命令行下删除指定的文件中的字符
如文件中有如下内容:
|陈颜|,||,||,||,| |,||,|73700164|,|0000010501|,|4|,|20040102|,||,|
怎样在命令行下删除其中的|字符,不用屏幕编辑器,用类似linux/unix下的sed

---------- Edited by willsort ----------
目前有三种方案:
1、使用EDLIN(MSDOS5/710,WindowsNT's),在2楼和4楼
2、使用FOR+SET,在4楼
3、使用字符串搜索替换的命令行工具,例如:HEXC
---------- Edited by willsort ----------


Last edited by willsort on 2005-8-2 at 23:41 ]

作者: willsort     时间: 2005-7-24 18:35
Re dvliu:

  在NT系列下,可以考虑类似sed的edlin,当然功能要弱一些。相应的操作如下,比如文本在test1.txt中,则:


edlin test1.txt
1r|(在此输入Ctrl+Z,不含括号)
e


Last edited by willsort on 2005-7-24 at 18:38 ]

作者: dvliu     时间: 2005-7-25 18:47
Originally posted by willsort at 2005-7-24 18:35:
Re dvliu:

  在NT系列下,可以考虑类似sed的edlin,当然功能要弱一些。相应的操作如下,比如文本在test1.txt中,则:


edlin test1.txt
1r|(在栮..

怎样在程序中实现此功能,不按ctrl-z,以及自动退出*,同时感谢willsort

作者: willsort     时间: 2005-7-26 16:44
Re dvliu:

  可以用以下的批处理程序:
:: Replace.bat - Sample of replace text
:: Will Sort - 12:47 2005-7-26
@echo off
copy test1.txt test2.txt > nul
echo e 100 "1r|" 1a 0d 0a "e" 0d 0a > _replace.dbg
for %%s in (rcx 9 n_replace.edl w q) do echo %%s >> _replace.dbg
debug < _replace.dbg
edlin test2.txt < _replace.edl
::以下的debug脚本是为文件去处最后的文本结束标记1A,它是edlin添加的
echo e 00 83 e9 01 > _replace.dbg
echo g=00 03 >> _replace.dbg
for %%s in (w q) do echo %%s>> _replace.dbg
debug test2.txt < _replace.dbg
::以上语句删除结束标记1A
for %%f in (_replace*.*) do del %%f


  也可以不用edlin实现类似的功能,比如以下的程序:
:: Replace2.bat - An other sample of replace text
:: Will Sort - 12:47 2005-7-26
@echo off
if "%1"=="" cmd /v:on /c %0 cmdshell & goto :EOF
if exist test2.txt del test2.txt
for /f "tokens=*" %%a in (test1.txt) do (
set line=%%a
echo !line:^|=!>> test2.txt
)


Last edited by willsort on 2005-7-26 at 21:30 ]