本帖最后由 newswan 于 2021-10-9 14:25 编辑
http://www.bathome.net/redirect.php?goto=findpost&pid=246478&ptid=60242- set "_cmd_=dir /s /b %sour%\*.txt | sed -r -e "s/^.+[\]//" | sort -u"
- set _cmdsed_=-r -e "/%exclude%/d" -e "/^\S+\s+\S+\s+\S+$/^!d" -e "s/SH/0/" -e "s/SZ/1/" -e "s/\s+/^|/g"
- set _cmdawk_=" { arr[$0]++ ; if ( arr[$0] == 1 ) { print $0 } } "
- for /f "usebackq tokens=* delims=" %%a in (`cmd /c "%_cmd_%"`) do (
- echo %%a
- (
- for /f "usebackq tokens=* delims=" %%b in (`dir /s /b "%sour%\%%a"`) do (
- type "%%~fb"
- ) | sed -r -e $a\
- ) | sed !_cmdsed_! | awk !_cmdawk_! > "%dest%\%%~nxa"
- )
复制代码 改成- for /f "usebackq tokens=* delims=" %%a in (`cmd /c "%_cmd_%"`) do (
- echo %%a
- (
- for /f "usebackq tokens=* delims=" %%b in (`dir /s /b "%sour%\%%a"`) do (
- type "%%~fb"
- ) | sed !_cmdsed_!
- ) | awk !_cmdawk_! > "%dest%\%%~nxa"
- )
复制代码 就会报错- sed: -e expression #1, char 2: unknown command: `_'
复制代码 请问在批处理中使用 sed awk 代码,有什么需要避坑的?
sed/awk -f 脚本文件 运行正常,但是要多个文件,也不方便 |