주 기능이 사용자가 로그 텍스트 파일에서 행/열을 grep시킬 수 있도록하는 C# 콘솔 프로그램이 있습니다.C# 프로그래밍 텍스트 파일에서 열/행을 grep하는 방법?
텍스트 파일 내에서 사용자가 특정 날짜 등에서 시작하는 모든 관련 줄의 그룹을 그립니다. "Tue Aug 03 2004 22:58:34"to "Wed Aug 04 2004 00:56 : 48 ". 따라서 처리 후 프로그램은 로그 텍스트 파일 내에있는 모든 데이터를 2 개의 날짜 사이에 출력합니다.
grep이나 파일에서 필요한 텍스트/데이터를 검색하기 위해 필터를 만드는 데 사용할 수있는 코드에 대해 조언을 구할 수 있습니까? 감사!
C# 프로그램 파일 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace Testing
{
class Analysis
{
static void Main()
{
// Read the file lines into a string array.
string[] lines = System.IO.File.ReadAllLines(@"C:\Test\ntfs.txt");
System.Console.WriteLine("Analyzing ntfs.txt:");
foreach (string line in lines)
{
Console.WriteLine("\t" + line);
// ***Trying to filter/grep out dates, file size, etc****
if (lines = "Sun Nov 19 2000")
{
Console.WriteLine("Print entire line");
}
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}
로그 텍스트 파일 예 : 당신은 string.Contains
허용하는 것보다 더 풍부한 방법으로 일치하는 라인을 선택 Regex
를 사용하여이 작업을 수행 할 수
Wed Jul 21 2004 16:58:48 499712 m... r/rrwxrwxrwx 0 0 8360-128-3
C:/Program Files/AccessData/Common Files/AccessData LicenseManager/LicenseManager.exe
Tue Aug 03 2004 22:58:34 23040 m... r/rrwxrwxrwx 0 0 8522-128-3
C:/System Volume Information/_restore{88D7369F-4F7E-44D4-8CD1-
F7FF1F6AC067}/RP4/A0002101.sys
23040 m... r/rrwxrwxrwx 0 0 9132-128-3
C:/WINDOWS/system32/ReinstallBackups/0003/DriverFiles/i386/mouclass.sys
23040 m... r/rrwxrwxrwx 0 0 9135-128-4 C:/System Volume
Information/_restore{88D7369F-4F7E-44D4-8CD1-F7FF1F6AC067}/RP4/A0003123.sys
23040 m... r/rrwxrwxrwx 0 0 9136-128-3
C:/WINDOWS/system32/drivers/mouclass.sys
Tue Aug 03 2004 23:01:16 196864 m... r/rrwxrwxrwx 0 0 4706-128-3
C:/WINDOWS/system32/drivers/rdpdr.sys
Tue Aug 03 2004 23:08:18 24960 m... r/rrwxrwxrwx 0 0 8690-128-3
C:/WINDOWS/system32/drivers/hidparse.sys
"StartsWith"는 처음 읽기만합니까? 왜냐하면 어떤 라인은 같은 시간에 여러 프로세스가 발생하는 양식으로서 날짜로 시작하지 않기 때문입니다. 감사. – JavaNoob
@JavaNoob : 예, "StartsWith"는 행의 시작 부분 만 검사합니다. 그래서 "Contains"도 언급했습니다 ... 여러 프로세스가 로그 파일을 손상시킬 수있는 것처럼 들리지만 수정이 필요합니다. 별개의 문제로 –
로그는 MACtimes의 용도로 사용되므로 여러 프로세스가 올바르게 사용됩니다. 위 질문에 로그 섹션을 편집 했으니 살펴보십시오. 감사. – JavaNoob