요구 사항 : 텍스트 파일을 구문 분석하고 특정 파일의 패턴을 다른 파일로 추출해야합니다. 출력 파일에 날짜가있는 행과 오류가 필요합니다.Windows 배치 파일에서 정규식을 사용하여 특정 패턴을 찾는 방법은 무엇입니까?
배치 파일 코드 :
findstr /r "^\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2},\\d{3} \<ERROR.*" server.log > "%CD%"/test.txt
pause
입력 파일 : Sample.log
2017-11-28 00:40:16,791 ERROR [org.jboss.weld.Bean] (ServerService Thread Pool -- 269) WELD-000019: Error destroying an instance
2017-11-28 00:40:16,791 INFO [stdout] (ServerService Thread Pool -- 269) [ERROR][faces context is null in context utils1]
2017-11-28 00:40:16,791 INFO [stdout] (ServerService Thread Pool -- 269) [ERROR][faces context is null in context utils1]
2017-11-28 00:40:16,791 ERROR [org.jboss.weld.Bean] (ServerService Thread Pool -- 269) WELD-000019: Error destroying an instance
2017-11-28 00:40:16,791 INFO [stdout] (ServerService Thread Pool -- 269) [ERROR][faces context is null in context utils1]
2017-11-28 00:40:16,791 INFO [stdout] (ServerService Thread Pool -- 269) [ERROR][faces context is null in context utils1]
예상 출력 :
2017-11-28 00:40:16,791 ERROR [org.jboss.weld.Bean] (ServerService Thread Pool -- 269) WELD-000019: Error destroying an instance
2017-11-28 00:40:16,791 ERROR [org.jboss.weld.Bean] (ServerService Thread Pool -- 269) WELD-000019: Error destroying an instance
그러나 현재 코드가 출력 파일의 모든 내용을 반환 . 시도한 단어 경계 \ 너무. 정규식의 제한 구현 findstr
년대 주어진 filename1
이 작업을 수행해야 당신의 sourcefilename을 포함
'd {3} \
Stephan
또한'\ d'가 없습니다. , '\ s' 및'+' – Stephan
@Stephan 예 .with/c "ERROR"오류가있는 줄을 필터링 할 수 있습니다 .Eg) 2017-11-28 00 : 40 : 16,791 INFO [stdout] (ServerService 스레드 풀 -269) 일부 문자열에 ERROR가 있습니다. \ d, \ s, +, count가없는 경우에는 다른 방법으로 –