标题: [文本处理] 批处理如何提取日志文件中一段内容? [打印本页]
作者: mdsqeh 时间: 2012-11-19 13:40 标题: 批处理如何提取日志文件中一段内容?
将****************Check OS Filesystem Status**********************
以下,*********check database status****************以上的内容提取到新文件。- ***************Check OS Filesystem Status**********************
-
-
-
- Filesystem GB blocks Free %Used Iused %Iused Mounted on
- /dev/hd4 1.00 0.45 55% 6574 6% /
- /dev/hd2 4.00 1.59 61% 41047 10% /usr
- /dev/hd9var 2.00 1.16 43% 97795 27% /var
- /dev/hd3 5.00 3.12 38% 2000 1% /tmp
- /dev/fwdump 8.00 8.00 1% 4 1% /var/adm/ras/platform
- /dev/hd1 2.00 2.00 1% 27 1% /home
- /proc - - - - - /proc
- /dev/hd10opt 2.00 1.91 5% 1752 1% /opt
- /dev/oraclelv 40.00 12.36 70% 133006 5% /oracle
- /dev/fslv00 50.00 49.88 1% 5 1% /reparch
- /dev/arch1lv 52.00 44.54 15% 21 1% /odsarch1
- /dev/ora_explv 50.00 27.60 45% 28 1% /ora_exp
- /dev/fslv01 390.75 85.97 78% 108 1% /orabackuplv
- ods2:/odsarch2 2.00 1.66 17% 6461 2% /odsarch2
- /dev/goldengatelv 170.25 160.25 6% 233 1% /gold
-
- *********check database status****************
复制代码
作者: tmplinshi 时间: 2012-11-19 14:00
本帖最后由 tmplinshi 于 2012-11-19 14:01 编辑
- sed -r "/\*+Check OS Filesystem Status\*+/,/\*+check database status\*+/!d" 1.log >o.log
复制代码
sed 下载地址:
http://bathome.net/thread-15605-1-4.html
作者: tmplinshi 时间: 2012-11-19 14:30
本帖最后由 tmplinshi 于 2012-11-19 14:32 编辑
- @echo off
- setlocal
-
- set inputfile="1.log"
- set bline="***************Check OS Filesystem Status**********************"
- set eline="*********check database status****************"
- set outputfile="output.log"
-
- set "_echo_start=" >%outputfile%
-
- for /f "tokens=1,* delims=:" %%a in (' findstr /n .* %inputfile% ') do (
- if not defined _echo_start (
- if /i "%%b" == %bline% (
- echo %%b
- set _echo_start=::
- )
- ) else (
- echo,%%b
- if /i "%%b" == %eline% goto finish
- )
- ) >>%outputfile%
-
- :finish
- echo finish
- pause
复制代码
作者: mdsqeh 时间: 2012-11-19 16:04
非常好用,谢谢楼上的两位,正在进一步改进中,力求完美高效,省事。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |