PS E:\xntutor\powershell> get-content file1.txt
The Add-Content cmdlet appends the content to the specified item or a file, such as adding words to the file.
We can specify the content by typing it in the cmdlet or by specifying an object which contains the content.
2020/1/31
最好一行~
PS E:\xntutor\powershell>
此示例中的cmdlet用于在当前目录中的PowerShell控制台上显示file1.txt文件的内容。
示例2: 从文本文件中获取前n行的内容
PS E:\xntutor\powershell> get-content file2.txt -totalcount 6
Line-1
Line-2
Line-3
Line-4
Line-5
Line-6
PS E:\xntutor\powershell>
此示例中的cmdlet显示文本文件中的特定行数。 -Totalcount参数显示内容的前6行。
示例3: 从文本文件中获取特定的内容行
PS E:\xntutor\powershell> (get-content file2.txt -totalcount 6)[2]
Line-3
PS E:\xntutor\powershell>
此示例中的cmdlet用于显示该内容的特定行。
示例4: 从文本文件获取内容的最后一行
PS E:\xntutor\powershell> get-content file2.txt -tail 2
PS E:\xntutor\powershell> get-content file2.txt -tail 4
Line-7
Line-8
PS E:\xntutor\powershell>
此示例中的cmdlet显示文件中内容的最后2行和4行。 -Tail参数获取文件的最后N行。
纠错/补充