[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 4# idwma


   有几个示例丢了

    ---------- Example 1: Get the content of a text file ----------

    1..100 | ForEach-Object { Add-Content -Path .\LineNumbers.txt -Value "This is line $_." }
    Get-Content -Path .\LineNumbers.txt

    -- Example 3: Get a specific line of content from a text file --

    (Get-Content -Path .\LineNumbers.txt -TotalCount 25)[-1]

    ----------- Example 7: Use Filters with Get-Content -----------

    Get-Content -Path C:\Temp\* -Filter *.log
本人所发所有贴子或代码, 诸大侠若认为有改进之处,请不吝赐教,感激不尽!

TOP

  1. $c = "get-Content"
  2. (get-help $c -Examples | Out-String) -replace '[\s\S]*?(.+Example\s\d:.+\n\s*\n[\s\S]*?\n\s*\n)[\s\S]*?\n\s*\n\s*\n','$1'
复制代码

TOP

回复 2# idwma


   感谢大侠支招, 匹配还是有点问题, 结果如下:
Get-Content
---------- Example 1: Get the content of a text file ----------
1..100 | ForEach-Object { Add-Content -Path .\LineNumbers.txt -Value "This is line $_." }
Get-Content -Path .\LineNumbers.txt
ate the `LineNumbers.txt` file. The variable `$_` represents the array values as each object is sent down the pipeline. The `Get-Content` cmdlet uses the P
--- Example 2: Limit the number of lines Get-Content returns ---
Get-Content -Path .\LineNumbers.txt -TotalCount 5
-- Example 3: Get a specific line of content from a text file --
(Get-Content -Path .\LineNumbers.txt -TotalCount 25)[-1]
The `Get-Content` command is wrapped in parentheses so that the command completes before going to the next step. `Get-Content`returns an array of lines, th
--------- Example 4: Get the last line of a text file ---------
Get-Item -Path .\LineNumbers.txt | Get-Content -Tail 1
This example uses the `Get-Item` cmdlet to demonstrate that you can pipe files into the `Get-Content` parameter. The Tail parameter gets the last line of t
---- Example 5: Get the content of an alternate data stream ----
PSPath        : Microsoft.PowerShell.Core\FileSystem::C:\Test\Stream.txt:DATA
PSChildName   : Stream.txt::$DATA
Stream        : :$DATA
# Retrieve the content of the primary, or $DATA stream.
Get-Content -Path .\Stream.txt -Stream $DATA
PSPath        : Microsoft.PowerShell.Core\FileSystem::C:\Test\Stream.txt::$DATA
PSChildName   : Stream.txt::$DATA
Stream        : :$DATA
Get-Content -Path .\Stream.txt -Stream NewStream
). By default `Get-Content` only retrieves data from the primary, or `$DATA` stream. Streams can be used to store hidden data such as attributes, security
------------------ Example 6: Get raw content ------------------
$raw = Get-Content -Path .\LineNumbers.txt -Raw
$lines = Get-Content -Path .\LineNumbers.txt
Write-Host "Raw contains $($raw.Count) lines."
Write-Host "Lines contains $($lines.Count) lines."
----------- Example 7: Use Filters with Get-Content -----------
Get-Content -Path C:\Temp\* -Filter *.log
--------- Example 8: Get file contents as a byte array ---------
$byteArray = Get-Content -Path C:\temp\test.txt -Encoding Byte -Raw
Get-Member -InputObject $bytearray
本人所发所有贴子或代码, 诸大侠若认为有改进之处,请不吝赐教,感激不尽!

TOP

  1. $c = "get-Content"
  2. ((get-help $c -Examples | Out-String) -split '\n') | foreach { $_.trim() } | sls ".+Example\s\d:.+|$c|\$"
复制代码

TOP

返回列表