标题: [文本处理] [已解决]如何提取文本中带指定标识(字符)的字符串? [打印本页]
作者: enoone1 时间: 2016-3-24 17:44 标题: [已解决]如何提取文本中带指定标识(字符)的字符串?
如何使用BAT得到如下结果(指定@标识的特殊内容):
@var1
@var2
@var3
@var4
@var5
@var6
@var7
作者: happy886rr 时间: 2016-3-24 19:41
回复 1# enoone1 - @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('type test.txt^|findstr "\@"') do (
- set "str=%%i"
- for /l %%j in (0 1 256) do (
- if "!str:~%%j,1!"=="@" (
- set gk=1
- ) else (
- if "!str:~%%j,1!"=="," (
- if !gk! equ 1 (
- set gk=0
- echo,
- )
- )
- if "!str:~%%j,1!"==" " (
- if !gk! equ 1 (
- set gk=0
- echo,
- )
- )
- if "!str:~%%j,1!"=="" (
- if !gk! equ 1 (
- set gk=0
- echo,
- )
- )
- )
- if !gk! equ 1 (
- set /p =!str:~%%j,1!<nul
- )
- )
- )
- pause>nul
复制代码
作者: pcl_test 时间: 2016-3-24 19:44
- //&cls&cscript -nologo -e:jscript "%~f0"<"test.txt"&pause&exit
- WSH.echo(WScript.StdIn.ReadAll().match(/@[^\s,@]+/g).join('\r\n'))
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |