|
Answer» Hi, I need some help on creating a report file by reading the 2nd to last line of text
Here's some examples below
https://ibb.co/mTf2HnY https://ibb.co/MZCv8dw
Basically I've tried playing around with a few formulas but none have got me the results I wanted, basically I have directories of text files, I'm looking at the 2nd to last line of text to get the last number. It's a pain loading up all these files on notepad or notepad ++ and scrolling down to find this out when it would be easier to create a batch file to get the results for me without having to open up these files.
So I'd like to generate a text file called 'report.txt' to gather both the filename and the 2nd to last line of text. HOWEVER the text files will always be unique and there will be more than ONE in the directory. The batch file will be in the same directory as the text files so all i'll have to do is run it.
The report file needs to display
Filename1 - 2nd to last line of Text From Filename1 Filename2 - 2nd to last line of Text From Filename2 Filename3 - 2nd to last line of Text From Filename3 etc...
So It'll look something like this
208634168_4.txt - media_1175.ts 208634168_5.txt - media_1200.ts 208634168_6.txt - media_1122.ts etc...
This is for all text files within the directory.
Thanks So you WANT the PENULTIMATE line...
Yes
echo off setlocal enabledelayedexpansion if exist report.txt DEL report.txt for %%A in (*.txt) do ( set "lastline=" set "thisline=" for /f "delims=" %%B in ('type "%%A"') do ( set lastline=!thisline! set thisline=%%B ) echo %%A !lastline! >> report.txt )
Thank you very much, I appreciate your help on this one
|