I am trying to fetch the first line (in fact first number) from my text file (whose data has been sorted in descending order) as below:
sorted.txt
:
10 9 8 7 6 5 4 3 2 1
But the output that I get is 1
. I expected it to be 10
.
I want to fetch this for further processing in a variable and the code that I used is as below:
set /p lastnum =< sorted.txt
pause
echo !lastnum!
pause
set /A lastNum = lastNum+1
echo !lastnum!
pause
Please let me know if I am doing something wrong. The length of the sorted.txt would vary everytime and the first value too. But always the highest number (which would be the first line) must be fetched.
I have tried the below PowerShell script too:
powershell.exe -Command $lastnum = Get-Content -LiteralPath "C:\offsite\sorted.txt" | ForEach-Object { $Output += [Int]($_.Trim()) }
But still it is not working.