Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

How to copy last line of .txt file into new .txt file?

$
0
0
Windows Server 2008 R2I'm totally new to PowerShell but was trying to use it to solve an issue with data files that come with the last row being a) short and b) containing the row count for the file. For example, a file with 77,571 rows with 34 columns per row ends with a row (row 77,572) that contains just the text 'Total Exported:77571' plus row end chars.I can get PowerShell to give me the content of the last row using: Get-Content filepath.txt | Select-Object -last 1However, I haven't figured out how to write that to a new file... Oh, and I'd like to remove that row from the file when I'm done. I can use a script that will parse all files in a directory. Anyone have time to help with this? Many Thanks!

Viewing all articles
Browse latest Browse all 467

Trending Articles