How to use Get-content to Count the Number of Lines in the File
Get-Content is a very powerful command and you will use it very often in your script.
Get-Content C:\temp\t1.txt
Where C:Temp is the folder path where the file is and t1.txt is the filename
(get-content c:\temp\t1.txt).count
This will give the number of Lines in the File
(get-content c:\temp\t1.txt -totalcount 5)
This will give you the first 5 lines
Also to see only Line where Particular word is matching use the below command
get-content C:\temp\t1.txt | select-string "get-c"
This will show lines only where "get-c" matches
Get-Content is a very powerful command and you will use it very often in your script.
- Lets say You want to see all Counte of file,type
Get-Content C:\temp\t1.txt
Where C:Temp is the folder path where the file is and t1.txt is the filename
- Now if you want to Count the number of Files in the file then, use
(get-content c:\temp\t1.txt).count
This will give the number of Lines in the File
- Now say you want to Pjust first 5 lines in the File, then use
(get-content c:\temp\t1.txt -totalcount 5)
This will give you the first 5 lines
Also to see only Line where Particular word is matching use the below command
get-content C:\temp\t1.txt | select-string "get-c"
This will show lines only where "get-c" matches
No comments:
Post a Comment