批处理怎么提取出指定文字的内容并另存文本
07-2121:27:00.628D/PowerManagerNotifier(452):onUserActivity:event=2,uid=100007-2121:2...
07-21 21:27:00.628 D/PowerManagerNotifier( 452): onUserActivity: event=2, uid=1000
07-21 21:27:00.632 D/PowerManagerService( 452): updateUserActivitySummaryLocked: mWakefulness=Awake, mUserActivitySummary=0x5, nextTimeout=21566653 (in 2996 ms)
07-21 21:27:00.632 D/PowerManagerService( 452): updateScreenStateLocked: mDisplayReady=true, newScreenState=2, mWakefulness=1, mWakeLockSummary=0x1, mUserActivitySummary=0x5, mBootCompleted=true
07-21 21:27:00.678 I/ActivityManager( 452): START u0 {act=android.settings.INTERNAL_STORAGE_SETTINGS flg=0x10000000 cmp=com.android.settings/.Settings$StorageSettingsActivity} from pid 24692
07-21 21:27:00.682 D/PowerManagerService( 452): handleSandman: canDream=false, mWakefulness=Awake
07-21 21:27:00.968 E/ActivityManager( 452): ANR in cn.com.nd.s
文本内容如上 要求查找出带有“ANR in ”字符的前5行并另存为B.TXT (不包括本行)。 展开
07-21 21:27:00.632 D/PowerManagerService( 452): updateUserActivitySummaryLocked: mWakefulness=Awake, mUserActivitySummary=0x5, nextTimeout=21566653 (in 2996 ms)
07-21 21:27:00.632 D/PowerManagerService( 452): updateScreenStateLocked: mDisplayReady=true, newScreenState=2, mWakefulness=1, mWakeLockSummary=0x1, mUserActivitySummary=0x5, mBootCompleted=true
07-21 21:27:00.678 I/ActivityManager( 452): START u0 {act=android.settings.INTERNAL_STORAGE_SETTINGS flg=0x10000000 cmp=com.android.settings/.Settings$StorageSettingsActivity} from pid 24692
07-21 21:27:00.682 D/PowerManagerService( 452): handleSandman: canDream=false, mWakefulness=Awake
07-21 21:27:00.968 E/ActivityManager( 452): ANR in cn.com.nd.s
文本内容如上 要求查找出带有“ANR in ”字符的前5行并另存为B.TXT (不包括本行)。 展开
1个回答
展开全部
@echo off&cd/d "%~dp0"
for /f "delims=:" %%i in ('type "a.txt"^|findstr/nc:"ANR in"')do (
for /L %%j in (1,1,5)do (
set/a n=%%i-%%j
call set #%%n%%=y))
(for /f "tokens=1* delims=:" %%i in ('type "a.txt"^|findstr/n ".*"')do (
if defined #%%i echo;%%j
))>"b.txt"
追问
如果多行出现ANR IN的字符就不行了 能解决不 谢谢 目的就是提出所有有出现ANR IN所在行的前5行的内容
追答
本来就是按有查找多处写的,如果关键串符合是没问题的
如果测试只找了一处,估计有两种可能,一是关键串大小写不一致(这个把其中第2行的/nc:改成/nic:即忽略大小写),二是中间空格数不等,也还是可以解决的,你再检查一下看是什么情况
忽略大小写,并有不等空格可以把第二行中findstr/nc:"ANR in"改为(中间有两空格加星号):
findstr/nirc:"ANR *in"
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询