1

これは単純であるべきだと思います。xcopyのログ出力をプレーン テキスト ファイル に書き込み"++++++++++++++++++++Tue 07/03/2018 0900 PM"ます。毎日のバックアップの前に、毎日の区切り文字を (文字通り) ログ ファイルに追加します。したがって、ファイルの最後の行は通常、次のようになります。

毎日の区切り

新しい日は、新しい区切り行などを追加します。

LAST 区切り文字とそれに続く行を に表示したいeof

私が試したスキーマはGET-Content, Select-String -Context 0,20機能しません。

PS私の検索文字列++++++++++++++++++++は正規表現ではなく、パスなどを認識しないと言います。何か助けはありますか?

メモリと時間は問題ではありません。これが単純すぎる場合は申し訳ありません。

4

4 に答える 4

0

個人的には、そのロギング形式を変更して、よりオブジェクトにやさしく、通常どおり使用できるようにします。

ただし、あなたが投稿した内容に基づいています。これには 1 つの方法があります。もっとエレガントな方法があると思いますが、これは q&d (迅速かつ汚い) です。午前 9:00 で、2100 は午後 9:00 です。8^} ... と言うと…</p>

# Get the lines in the file
($DataSet = Get-Content -Path '.\LogFile.txt')

# Results

++++++++++++++++++++Mon 07/02/2018 0900 PM
0 Files(s) copied
 Xcopy SUCCEEDED K:\ to J:\MyUSBBackups Mon 07/02/2018 0900 PM
0 Files(s) copied
 Xcopy SUCCEEDED K:\ to J:\MyUSBBackups\OutlookBak Mon 07/02/2018 0900 PM
++++++++++++++++++++Mon 07/03/2018 0900 PM
0 Files(s) copied
 Xcopy SUCCEEDED K:\ to J:\MyUSBBackups Mon 07/02/2018 0900 PM
0 Files(s) copied
 Xcopy SUCCEEDED K:\ to J:\MyUSBBackups\OutlookBak Mon 07/02/2018 0900 PM



 # Get the index of the LastDateEntry, using a string match (RegEx)
($LastDateEntry = (Get-Content -Path '.\LogFile.txt' | %{$_ | Select-String -Pattern '[+].*'}) | Select -Last 1)

# Results

++++++++++++++++++++Mon 07/03/2018 0900 PM


# Get the LastDateEntryIndex
($DateIndex = (Get-Content -Path '.\LogFile.txt').IndexOf($LastDateEntry))

# Results

5



 # Get the data using the index
ForEach($Line in $DataSet)
{
    If ($Line.ReadCount -ge $DateIndex)
    {
    Get-Content -Path '.\LogFile.txt' | Select-Object -Index ($Line.ReadCount)
    }
}

# Results

++++++++++++++++++++Mon 07/03/2018 0900 PM
0 Files(s) copied
 Xcopy SUCCEEDED K:\ to J:\MyUSBBackups Mon 07/02/2018 0900 PM
0 Files(s) copied
 Xcopy SUCCEEDED K:\ to J:\MyUSBBackups\OutlookBak Mon 07/02/2018 0900 PM
于 2018-07-05T04:02:43.060 に答える