Package: read the txt file and print the last 10 lines, separated by commas

I have a simple batch file that reads the last 10 lines from a batch file and then outputs these 10 lines to a new txt file, but I need it to be output as a line / line, separated by commas.

@echo off
for /f %%i in ('find /v /c "" ^< C:\Path To File\File.txt') do set /a lines=%%i
set /a startLine=%lines% - 10
more /e +%startLine% C:\Path To File\File.txt > Output.txt

Also, is it possible to reorder the lines in the new txt file so that the last line is at the beginning of the line, separated by commas.

An example of what I need:

line1
line2
line3
line4

output as

line4, line3, line2, line1
+4
source share
1 answer

This small power shell script wil do:

$Lines = Get-Content .\Lines.txt|select -last 10
($Lines[($Lines.Length-1)..0]) -join(', ')|Set-Content Lines-new.txt

To be in a topic wrapped in a package:

@echo off
Powershell -command "($Lines=GC .\Lines.txt|select -last 10);(($Lines[($Lines.Length-1)..0]) -join(' ')|Set-Content Lines-New.txt)"
+1
source

Source: https://habr.com/ru/post/1666502/


All Articles